Allow preserving "is-attribute" with JsonNode to write output as attribute value

Aperta
#217 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

Inizia riproducendo il problema con i metodi di scrittura di JSON e XmlMapper mostrati nel report, quindi esamina il percorso di serializzazione XML per la gestione di JsonNode. Il lavoro è completato quando un campo annidato selezionato, come OrgnlIntrBkSttlmAmt, conserva Ccy come attributo XML, mentre la struttura JsonNode rimanente viene scritta come elementi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I want to map a JsonNode to a XML. If I directly call XmlMapper write methods, this converts all the SubNode's of JsonNode as XMLElement which is fine.

But I want one of the field/subfield convert as XMLAttribute.

Is there a way to tell the mapper 'this node is not element, please convert it as attribute?'

Check the OrgnlIntrBkSttlmAmt field below (XML and json format is not preserved, sorry for that)

A sample JSON file is as follows :

{
    "FIToFIPmtCxlReq": {
        "Undrlyg": [
            {
                "TxInf": [
                    {
                        "CxlId": "3EfXiRbNk517MHY",
                        "OrgnlInstrId": "0amcNeP5QhXnY9x3Ykkj5TScqoTQF",
                        "OrgnlIntrBkSttlmAmt": {
                            "Ccy": "EUR",
                            "Value": 1462216
                        }
                    }
                ]
            }
        ]
    }
}

The converted XML is as follows

<?xml version='1.1' encoding='UTF-8'?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.056.001.01">
	<FIToFIPmtCxlReq>
		<Undrlyg>
			<TxInf>
				<CxlId>3EfXiRbNk517MHY</CxlId>
				<OrgnlInstrId>0amcNeP5QhXnY9x3Ykkj5TScqoTQF</OrgnlInstrId>
				<OrgnlEndToEndId>yy</OrgnlEndToEndId>
				<OrgnlIntrBkSttlmAmt>
					<Ccy>EUR</Ccy>
					<Value>1462216</Value>
				</OrgnlIntrBkSttlmAmt>
			</TxInf>
		</Undrlyg>
	</FIToFIPmtCxlReq>
</Document>

The requested output is as follows:

<?xml version='1.1' encoding='UTF-8'?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.056.001.01">
	<FIToFIPmtCxlReq>
		<Undrlyg>
			<TxInf>
				<CxlId>3EfXiRbNk517MHY</CxlId>
				<OrgnlInstrId>0amcNeP5QhXnY9x3Ykkj5TScqoTQF</OrgnlInstrId>
				<OrgnlEndToEndId>yy</OrgnlEndToEndId>
				<OrgnlIntrBkSttlmAmt Ccy="EUR">1462216</OrgnlIntrBkSttlmAmt>
			</TxInf>
		</Undrlyg>
	</FIToFIPmtCxlReq>
</Document>
Lingua principale
Java
Stelle
636
Fork
250
Merge medio
7h 10m
PR unite (30g)
8

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di FasterXML/jackson-dataformat-xml

Tutte le issue di FasterXML/jackson-dataformat-xml

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.