Allow custom prefix for attributes name
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-api-design
Direzione di ricerca
Inizia tracciando XMLMapper e il MapSerializer esistente per la gestione in ingresso e in uscita delle voci della mappa, quindi individua il corrispondente percorso di deserializzazione. Il lavoro è completato quando un prefisso degli attributi configurabile distingue gli attributi dagli elementi, supporta il comportamento di compatibilità per null e per un prefisso vuoto e gestisce l’esempio XML fornito in entrambe le direzioni.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
The default behavior of the XML deserialization, when reading into non-bean objects is to treat attributes the same way as elements. On serialization, I could not find way to generate attributes - all hash map entries were converted into objects. The only way I found to be able to tell the difference between elements and attributes in the outbound was to write a custom serializer, still working on trying to get this done with inbound serializer.
Example:
var mapper = new XMLMapper();
Object value = mapper.readValue("<DATA FOO="BAR"> <COLOR> WHITE </COLOR> </DATA>
The resulting object will be set of LinkedHashMap, with no obvious way to tell the different between the attributes and the elements.
(LinkedHashMap) {
"FOO": "BAR",
"COLOR": "WHITE",,
}
Would like to suggest/ask for a new setting on the XMLMapper that will allow specifying a prefix for attributes. On the inbound, each attribute will be stored with the prefix inside the key. In my case, I'm using '@' as prefix, there the example above will result in
var mapper = new XMLMapper();
Object value = mapper.readValue("<DATA FOO="BAR"> <COLOR> WHITE </COLOR> </DATA>
// Define Custom Prefix
mapper.setAttributPrefix("@");
Result:
(LinkedHashMap) {
// FOO is prefixed with '@'
"@FOO": "BAR",
"COLOR": "WHITE",,
}
For the Serializer - same logic in reverse. If map key starts with the designated prefix it will be converted into an attribute (with the prefix removed). For backward compatibility:
- If the prefix is NULL (or not set), current logic remain
- If the prefix is "" (empty string), every map entry will be converted into attribute with the same name (subject to the text attribute, which already has special handling).
While the custom serializer was short to write - It took some googling/effort to write, and I believe it's not as robust as the built in logic that is currently implemented in the MapSerializer. Will address lot of use cases when it's critical separate attribute/elements, without having to predefined beans.
- 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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di FasterXML/jackson-dataformat-xml
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
FasterXML/jackson-dataformat-xml#931 · 3 commenti ·
-
XmlMapper with `FAIL_ON_UNKNOWN_PROPERTIES` fails on whitespace-only elementForse già presa @arimu1 l’ha presa 89 giorni fa. Apertato-evaluate
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
3.x
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
FasterXML/jackson-dataformat-xml#787 · 1 commento ·
Tutte le issue di FasterXML/jackson-dataformat-xml
Issue simili
-
Cleanup: restore the interrupt flag in AiFailureAnalyzerForse già presa @Rishankgupta08 l’ha presa oggi. Apertagood first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
seleniumboot/selenium-boot#258 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
dense-analysis/ale#5181 ·
-
bug subsystem:agent-harness triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
ShaftHQ/SHAFT_ENGINE#8043 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
johanhaleby/occurrent#1505 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno