Using `@XmlAttribute` for property with non-scalar type prevents serialization as attribute for other properties

Aperta
#128 5 commenti 0 reazioni 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
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

Start with the Bug2.main reproducer and run the two XmlMapper serialization cases shown in the issue. Trace how the JAXB @XmlAttribute annotations are handled for the non-scalar Bean field, then verify that the behavior for start, bean, and end matches an explicitly agreed outcome and add a regression test if the project’s test location is identified.

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

Descrizione

has-failing-test

Look at the last line of this class.
Incorrect using @XmlAttribute for a bean serialization breaks a serialization of other properties.
I excepted to see an error or bean value as an attribute value.

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

public class Bug2 {

    @XmlRootElement(name = "bean")
    public static class Bean {

    }

    @XmlRootElement(name = "root")
    public static class Container {
        @XmlAttribute(name = "start")
        public String start;

        @XmlAttribute(name = "bean")
        public Bean bean;

        @XmlAttribute(name = "end")
        public String end;
    }

    public static void main(String[] args) throws JsonProcessingException {
        XmlMapper xmlMapper = new XmlMapper();
        xmlMapper.registerModule(new JaxbAnnotationModule());
        xmlMapper.registerModule(new JacksonXmlModule());

        Container container = new Container();
        container.start = "!start";
        container.end = "!end";
        System.out.println(xmlMapper.writeValueAsString(container)); // print <root xmlns="" start="!start" end="!end"></root>

        Bean bean = new Bean();
        container.bean = bean;
        System.out.println(xmlMapper.writeValueAsString(container)); // print <root xmlns="" start="!start"><bean></bean><end>!end</end></root>
    }
}

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.