unmarshalling

JAXB override @XmlElement type of list

限于喜欢 提交于 2020-01-02 14:04:58
问题 There's a simple class Bean1 with a sublist of type BeanChild1 . @XmlRootElement(name="bean") @XmlAccessorType(XmlAccessType.PROPERTY) public static class Bean1 { public Bean1() { super(); } private List<BeanChild1> childList = new ArrayList<>(); @XmlElement(name="child") public List<BeanChild1> getChildList() { return childList; } public void setChildList(List<BeanChild1> pChildList) { childList = pChildList; } } public static class BeanChild1 { ... } I am trying to override the class, to

jaxb unmarshalling giving NULL to anytype element in xsd

一曲冷凌霜 提交于 2020-01-02 10:23:37
问题 I am getting NULL value eventhough there is some value in xml using jaxb unmarshalling. Element in xsd <xs:element name="Account" minOccurs="1" maxOccurs="unbounded" > does not have type attribute. In its respective Java class AccountNo become java.lang.Object type. but after Unmarshalling xml <AccountNo>GDF23232223</AccountNo> output comes [AccountNo=NULL] My unmarshalling code jaxbContext = JAXBContext.newInstance("net.process"); Unmarshaller jaxbUnmarshaller = jaxbContext

Customizing error handling of JAXB unmarshall process

痴心易碎 提交于 2020-01-02 05:01:08
问题 Assuming I have a schema that describes a root element class Root that contains a List<Entry> where the Entry class has a required field name. Here is how it looks in code: @XmlRootElement class Root{ @XmlElement(name="entry") public List<Entry> entries = Lists.newArrayList(); } @XmlRootElement class Entry{ @XmlElement(name="name",required=true) public String name; } If I supply the following XML for unmarshalling: <root> <entry> <name>ekeren</name> </entry> <entry> </entry> </root> I have a

JAXB: Namespace annotation not inherited during unmarshalling - regression in JDK 1.8_102?

瘦欲@ 提交于 2019-12-30 22:57:16
问题 I ran into a situation where JAXB refuses to unmarshal an XML element unless the corresponding Java field has a namespace annotation. This behavior only started in JDK 1.8.0_111 (or possibly in 102). Earlier versions of JDK 1.8 work. Test case: Java class (shortened): package my.package; @XmlRootElement(name = "MyElement", namespace="myns") public class MyElement { @XmlElement(name = "subEl") private String subEl; } XML: <MyElement xmlns="myns"> <subEl>text1</subEl> </MyElement> package-info

JAXB: Namespace annotation not inherited during unmarshalling - regression in JDK 1.8_102?

大兔子大兔子 提交于 2019-12-30 22:56:13
问题 I ran into a situation where JAXB refuses to unmarshal an XML element unless the corresponding Java field has a namespace annotation. This behavior only started in JDK 1.8.0_111 (or possibly in 102). Earlier versions of JDK 1.8 work. Test case: Java class (shortened): package my.package; @XmlRootElement(name = "MyElement", namespace="myns") public class MyElement { @XmlElement(name = "subEl") private String subEl; } XML: <MyElement xmlns="myns"> <subEl>text1</subEl> </MyElement> package-info

JAXB: Namespace annotation not inherited during unmarshalling - regression in JDK 1.8_102?

∥☆過路亽.° 提交于 2019-12-30 22:55:14
问题 I ran into a situation where JAXB refuses to unmarshal an XML element unless the corresponding Java field has a namespace annotation. This behavior only started in JDK 1.8.0_111 (or possibly in 102). Earlier versions of JDK 1.8 work. Test case: Java class (shortened): package my.package; @XmlRootElement(name = "MyElement", namespace="myns") public class MyElement { @XmlElement(name = "subEl") private String subEl; } XML: <MyElement xmlns="myns"> <subEl>text1</subEl> </MyElement> package-info

Marshalling/Unmarshalling Java superclass and subclasses using JAXB

拟墨画扇 提交于 2019-12-30 14:49:08
问题 I've been experimenting with JAXB tutorials and have managed to get code working that generates an XML file from a Java object and then is able to use the XML to generate a Java object. At the moment it reads multiple instances of the same class to create an XML file similar to the one below <Car> <regplate>TR54</regplate> <colour>red</colour> <energyrating>5</energyrating> </Car> <Car> <regplate>BN04 THY</regplate> <colour>yellow</colour> <energyrating>3</energyrating> </Car> <Car> <regplate

How to Unmarshal jSON with dynamic key which can't be captured as a `json` in struct: GOlang [duplicate]

拥有回忆 提交于 2019-12-30 11:04:15
问题 This question already has answers here : How to parse/deserialize dynamic JSON (2 answers) Closed 6 months ago . I have this struct defined: type X struct { A string `json:"a_known_string"` B string `json:"b_known_string"` } This sample JSON: jsnStr := [read in from a file and printed out to confirm] It is: { "any string" : { "a_known_string" : "some value", "b_known_string" : "another value" } } If it was just the struct, I could: var x X err := json.Unmarshal(jsnStr, &x) But I need to

How to Unmarshal jSON with dynamic key which can't be captured as a `json` in struct: GOlang [duplicate]

∥☆過路亽.° 提交于 2019-12-30 11:03:07
问题 This question already has answers here : How to parse/deserialize dynamic JSON (2 answers) Closed 6 months ago . I have this struct defined: type X struct { A string `json:"a_known_string"` B string `json:"b_known_string"` } This sample JSON: jsnStr := [read in from a file and printed out to confirm] It is: { "any string" : { "a_known_string" : "some value", "b_known_string" : "another value" } } If it was just the struct, I could: var x X err := json.Unmarshal(jsnStr, &x) But I need to

JAXB: How to marshal objects in lists?

时光总嘲笑我的痴心妄想 提交于 2019-12-28 01:50:13
问题 Perhaps a stupid question: I have a List of type <Data> which I want to marshal into a XML file. This is my class Database containing an ArrayList ... @XmlRootElement public class Database { List<Data> records = new ArrayList<Data>(); public List<Data> getRecords() { return records; } public void setRecords(List<Data> records) { this.records = records; } } ...and this is class Data: // @XmlRootElement public class Data { String name; String address; public String getName() { return name; }