Problem with JAXB unmarshalling classes that have the same name in @XmlRootElement

sboehm

Neues Mitglied
Hi guys,

I am receiving some simple XML messages from a device. Here two examples:

[XML]
<Response Action="Initialize" Result="1" Lane=”1” />
[/XML]
and
[XML]
<Response Action="CancelTransaction" Result="0" />
[/XML]

Well, now I have to unmarshall these messages to two different Java objects. I am using JAXB's for this annotations:

Java:
@XmlRootElement(name = "Response")
public class InitializeResponseMessage {

	@XmlAttribute(name = "Action")
	private Integer action;

	@XmlAttribute(name = "Result")
	private Integer result;

	@XmlAttribute(name = "Lane")
	private Integer lane;

	public InitializeResponseMessage() {}
}
and
Java:
@XmlRootElement(name = "Response")
public class CancelTransactionResponseMessage {

	@XmlAttribute(name = "Action")
	private Integer action;

	@XmlAttribute(name = "Result")
	private Integer result;

	public InitializeResponseMessage() {}
}

The problem now is that the unmarshaller does not recognize that the two XML messages are different object. Of course not because they have the same XML tag. The unmarshaller used the Java type that is defined last when creating the JAXBContext instance.

It there a possibility to decide with the "Action" attribute which Java object the unmarshaller has to create? ???:L
 

sboehm

Neues Mitglied
the problem is that the unmarshaller creates objects only of one time (the last java class in the list for the JAXB context creation)

the attributes are set if both classes contains them (e.g. action) for a xml initialize message xml string a wrong java class is used and the lane attribute is not set because it does only exist in the initialize message class
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
S Jaxb Unmarshalling Problem XML & JSON 4
P JAXB-Problem XML & JSON 1
B JPA + JAXB Mapping Problem XML & JSON 2
K JAXB und Maps -> Marshalling-Problem XML & JSON 6
F Problem mit JAXB Unmarshaller XML & JSON 2
H JAXB CUSTOMIZATION PROBLEM XML & JSON 2
O XPATH Problem - Anfänger XML & JSON 4
so_ein_Komischer Problem mit Clean and Build XML & JSON 1
W Problem mit dem mit XML sortierung XML & JSON 2
E einfaches Problem XML + XSD + jedit XML & JSON 2
S Xslt Problem XML & JSON 2
B JasperReport Problem in Runtime XML & JSON 2
R Problem bei: XML und XSL zu HTML XML & JSON 2
M Read / write Problem beim ByteStrom XML & JSON 2
M XML write Problem zweiter Ansatz XML & JSON 3
M XML read Problem XML & JSON 4
M XML write Problem XML & JSON 2
whitenexx Problem beim parsen von Facebook XML XML & JSON 3
M XML Unicode Problem XML & JSON 2
S XJC --> Java-Objects compile Problem XML & JSON 4
F XPath-Problem mit DOM4J XML & JSON 8
T XPath Problem: finden einer Node nach Attributswert XML & JSON 2
G Problem beim schreiben von XML in eine File XML & JSON 2
S Encoding Problem XML & JSON 7
B Problem beim löschen von ChildNodes aus einem XML-DOM XML & JSON 3
E JDOM - Problem beim Zusammenfügen zweier Dateien XML & JSON 2
M JExcelAPI (JXL) Encoding Problem XML & JSON 11
S DOM Parsen Problem mit HTML Sonderzeichen XML & JSON 4
A aus xml --> html Problem XML & JSON 3
Y stax Problem XML & JSON 3
slawaweis Problem mit XSLT (wahrscheinlich ein Bug in Java 6) XML & JSON 16
T Problem beim Parsen von Attribut xmlns="urn:com:test&qu XML & JSON 6
P XPath Problem XML & JSON 2
J Problem beim XML-Lesen XML & JSON 2
M Problem mit FOP in Java Programm XML & JSON 2
S Problem mit XPath XML & JSON 4
J Problem mit compile einer XSD XML & JSON 3
N jdom problem beim lesen von child elementen XML & JSON 5
N problem bei xml lesen mit jdom XML & JSON 2
A XPath Problem XML & JSON 2
W JDOM element ändern funzt nich :( [problem gelöst] XML & JSON 3
G Problem mit XML-Schema Validierung mit Java XML & JSON 12
B jdom: getChildren() problem XML & JSON 4
H XSL-FO Problem mit If XML & JSON 2
loadbrain XPath Problem XML & JSON 2
T addContent / Problem mit Variable XML & JSON 2
F JDOM und XPath - Problem mit Namespace ohne Prefix XML & JSON 5
8 SAXParser Problem, startElement wird nicht ausgeführt XML & JSON 2
M Java und XSLT: Performanz-Problem XML & JSON 5
X JDOM SAXBuilder Validationschema - Problem XML & JSON 8
G Problem mit getContent XML & JSON 4
K stax problem XML & JSON 2
S Problem mit SAX XML & JSON 6
A Problem mit JasperReport XML & JSON 6
G DOCTYPE Problem beim Transformer/TransformerFactory etc. XML & JSON 13
C XSD Problem XML & JSON 16
R Problem bei Erstellung von XML(JDOM) XML & JSON 3
R Problem mit SAX-Parser characters() XML & JSON 7
M XPath Problem im Zusammenhang mit document() XML & JSON 2
P Problem beim erstellen eines neuen Elements (JDOM) XML & JSON 5
Z Problem mit getNodeValue() und setNodeValue() in DOM XML & JSON 6
M XPATH und RSS (Problem namespaces) XML & JSON 7
P SAXParser problem? XML & JSON 2
S Problem beim Erstellen eines pdfs XML & JSON 3
V Problem mit xsd XML & JSON 2
P XML mit hilfe von JDOM abspeichern macht Problem XML & JSON 6
G Problem mit addContent() XML & JSON 4
B DTD Problem - Reihenfolge der Einträge XML & JSON 2
R Problem beim Auslesen von Attributen XML & JSON 4
K Problem mit ant/java web services XML & JSON 4
K xml Datei mit JDOM erzeugen, Problem Namespaces XML & JSON 1
P Problem mit XML und DOM XML & JSON 2
8u3631984 jaxb XML Mapper - Root Element mit Attribut XML & JSON 20
W jaxws jaxb wsdl Java-Klassen generieren und binding.xml verwenden XML & JSON 1
Rakshan Unmarshalling multiple namespaces with jaxb XML & JSON 0
B JAXB und HTML XML & JSON 1
E JAXB und java.nio.file.Path XML & JSON 4
W jaxb-api XML Feld nicht gesendet setzt das Defaultvalue nicht XML & JSON 3
S Muss ich bei JAXB immer noch eine zusaetzliche List-Wrapper Klasse erstellen wenn ich mehrere Objekte serialisieren will..? XML & JSON 1
S JAXB mit mehreren zusammenhängenden .xsd-Files XML & JSON 0
N JAXB: Überflüssiges Wrapper-Tag für Map-Einträge XML & JSON 0
D JAXB mit Map und Color XML & JSON 2
K JAXB-XML unvollständig XML & JSON 1
K JAXB Unmarshelling XML & JSON 1
E JAXB und abstrakte Klasse(n) XML & JSON 0
B JAXB - Unmarshal -> Kinder bekommen und die Kinder von den Kinder XML & JSON 7
B JAXB - Marshal ArrayList XML & JSON 2
B JAXB - java.util.Locale does not have a no-arg default constructor XML & JSON 2
B JAXB-Fehler bei REST-Api XML & JSON 0
M JAXB HashMap Dynamisches Laden XML & JSON 0
M JAXB @XMLID und @XMLIDREF, wie Daten hinzufügen XML & JSON 2
A JAXB: XMLMixed generieren XML & JSON 0
R [JAXB] XmlRootElement und XmlType gemeinsam nutzen XML & JSON 0
I XML to Object - Mapping mit JAXB 1.0 XML & JSON 1
L JAXB - Generischen Wert mit Liste belegen XML & JSON 1
M XML-Datei mit JAXB und 2 Namespaces XML & JSON 0
K JAXB Annotation @XMLRootElement vererben XML & JSON 0
F JAXB Unmarshal - Kein "default Constructor" XML & JSON 2
F.S.WhiTeY JAXB: Schema nicht "erben" XML & JSON 2
B JAXB - manuell Klassen aus xsd XML & JSON 3

Ähnliche Java Themen

Neue Themen


Oben