0
上の値をXMLにJSONに変換し、私は私が持っているとOrdenクラス@JsonRootName("orden")
で構成し、すべてのプロパティに@JsonProperty
を追加したルートタグのJava - ルートタグ
の値とXML形式にJSONに変換する必要があります。
実際には、私はJSONをXMLに変換するが、「子ノードの値」という実装はありません。
これは私のコンバータの実装です:
public static String convertJsonObjectToXml (Object obj) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String jsonString = mapper.writeValueAsString(obj);
JSONObject json = new JSONObject(jsonString);
String xml = XML.toString(json);
return xml;
}
は、その実装の結果がこれです:
<orden>
<formaOp>C</formaOp>
<agente>109</agente>
<tipo>C</tipo>
<precio>2.5</precio>
<tipoVenc>72</tipoVenc>
<idOrigen>156934</idOrigen>
<instrumento>TS</instrumento>
<ejecucion>SINCRONICA</ejecucion>
<agenteCtpte>3</agenteCtpte>
<comitente>0</comitente>
<fechaOrigen>2013-10-09T08:04:13</fechaOrigen>
<cantidad>10</cantidad>
</orden>
しかし、私は、短い非友好的または何
以下のXMLの形式の名前を必要とします<orden idOrigen="156934" fechaOrigen="2014-02-19T15:11:44.000-03:00"
agente="109" agenteCtpte="3" tipo="C" ejecucion="SINCRONICA" instrumento="TS"
cantidad="10" precio="2.5" formaOp="C" tipoVenc="72"/>
すべてのアイデア?ありがとう!
なぜ2つの異なるJSONライブラリを使用していますか? ---とにかくJSONに変換するためにJackson ObjectMapperを使用しているので、JAXBを使ってオブジェクトをXMLに変換してみませんか?そうすれば、JAXBアノテーションを使用してXML生成を完全に制御することができます。 – Andreas
Thaks!私はあなたのコメントに基づいて答えを入れます –