unmarshalling

How to marshal/unmarshal Java objects with private fields using JAXB

荒凉一梦 提交于 2019-11-30 15:28:08
问题 I know the basics of the JAXB API, but I am stuck with something I am trying to do, and I am not sure whether it is actually possible. Details are as follows: I have a class called Book with 2 public instance variables of type String: @XmlRootElement(name="book") public class Book { public String title; public String author; public Book() { } } I have a another class called Bookshop with 1 public instance variable of type ArrayList: @XmlRootElement(name="bookshop") public class Bookshop {

How to marshal/unmarshal Java objects with private fields using JAXB

大城市里の小女人 提交于 2019-11-30 14:30:20
I know the basics of the JAXB API, but I am stuck with something I am trying to do, and I am not sure whether it is actually possible. Details are as follows: I have a class called Book with 2 public instance variables of type String: @XmlRootElement(name="book") public class Book { public String title; public String author; public Book() { } } I have a another class called Bookshop with 1 public instance variable of type ArrayList: @XmlRootElement(name="bookshop") public class Bookshop { @XmlElementWrapper(name="book_list") @XmlElement(name="book") public ArrayList<Book> bookList; public

Partial Unmarshalling of an XML using JAXB to skip some xmlElement

守給你的承諾、 提交于 2019-11-30 07:58:36
I want to unmarshal an XML file to java object using JAXB. The XML file is very large and contains some nodes which I want to skip in some cases to improve performance as these elements are non editable by client java program. A sample XML is as follows: <Example id="10" date="1970-01-01" version="1.0"> <Properties>...</Properties> <Summary>...</Summary> <RawData> <Document id="1">...</Document> <Document id="2">...</Document> <Document id="3">...</Document> ------ ------ </RawData> <Location></Location> <Title></Title> ----- // more elements </Example> I have two use cases: unmarshal into

How to validate an XML against schema using JAXB?

天涯浪子 提交于 2019-11-30 06:46:34
I am working with XML and JAXB as I am unmarshalling and marshalling the XML into Java objects and vice versa. Now I am trying to validate our XML against our schema(test.xsd). Suppose if any required field is missing in my XML, then I would like to know which field is missing after validating the XML against schema test.xsd. public void unmarshal(final InputStream is) { final XMLInputFactory factory = XMLInputFactory.newInstance(); final XMLStreamReader reader = factory.createXMLStreamReader(is); Object req = unmarshaller.unmarshal(reader); // how would I validate here? } How would I validate

How to unmarshall SOAP response using JAXB if namespace declaration is on SOAP envelope?

守給你的承諾、 提交于 2019-11-30 00:16:22
JAXB can only unmarshall an XML if the soap envelope has already been removed. However, the SOAP response I'm trying to unmarshall has its namespace declaration on the soap envelope. If I remove the soap envelope, the namespace declaration will also be removed. As such the prefix of the tags will be referring to none. This causes JAXB to throw an error. How can I unmarshall a SOAP response using JAXB if the namespace is declared on the SOAP envelope? A similar sample of the XML that I need to unmarshall is below: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns

Enums don't match schema: problem with jaxb or xsd?

时光毁灭记忆、已成空白 提交于 2019-11-29 21:34:27
问题 I'm trying to use JAXB to unmarshal this file into Java objects. I know that there's a problem with SAX in J6 that rejects the maxOccurs line, and I've changed it to unbounded . However, when I xjc it, it's not creating all the classes & enums I need. For example, there should be a educationLevelType enum. What's more, I'ved tried MS's xsd unmarshaller, it it creates everything correctly. Can someone with more experience than I look at this and tell me what I'm missing? Is there something

Unmarshal JSON data of unknown format [duplicate]

爱⌒轻易说出口 提交于 2019-11-29 18:52:23
This question already has an answer here: Unmarshal JSON with unknown fields [duplicate] 7 answers My JSON is in the following format: { 'Math': [ {'Student1': 100.0, 'timestamp': Timestamp('2017-06-26 15:30:00'), 'Student2': 100.0, 'Student3': 97.058823442402414}, {'Student1': 93.877550824911907, 'timestamp': Timestamp('2017-06-26 15:31:00'), 'Student2': 100.0, 'Student5': 100.0}, {'Student8': 100.0, 'timestamp': Timestamp('2017-06-26 15:32:00'), 'Student10': 100.0, 'Student4': 100.0} ], 'English': [ {'Student1': 100.0, 'timestamp': Timestamp('2017-06-26 15:30:00'), 'Student5': 100.0,

JAXB XMLAdapter method does not throws Exception

余生颓废 提交于 2019-11-29 16:59:25
问题 I am using JAXB XMLadapter to marshal and unmarshal Boolean values. The application's XML file will be accessed by C# application also. We have to validate this XML file and this is done using XSD. C# application writes "True" value for Boolean nodes. But the same does get validated by our XSD as it only allows "true/false" or "1/0". So we have kept String for boolean values in XSD and that string will be validated by XMLAdapter to marshal and unmarshal on our side. The XML Adapter is as

Go Unmarshal nested unknown fields

心不动则不痛 提交于 2019-11-29 16:29:01
I forked a great project here , and have just been having a mess around with it learning some go. My issue I can't figure out is some things about custom unmarshaling, if you see here you can see this unmarshals the Thing struct which holds a Data interface{} field that is then unmarshalled using the Kind string field. This all works great except the nested situations. So the best thing is an example: Just say you have Thing struct that's kind is a listing , thus the Thing.Data this is unmarshalled to type listing . Then listing has 3 Children of type link that is held in the Children []Thing

Problem in implementing Parcelable containing other Parcelable

有些话、适合烂在心里 提交于 2019-11-29 15:07:09
问题 I'm implementing Parcelable class that has another Parcelable insde. In OuterParcelable class: @Override public void writeToParcel(Parcel dest, int flags) { Bundle tmp = new Bundle(); tmp.putParcelable("innerParcelable", mParcelable); dest.writeBundle(tmp); and then: public OuterParcelable(Parcel parcel) { super(); Bundle b = parcel.readBundle(); mParcelable = b.getParcelable("innerParcelable"); and: public OuterParcelable createFromParcel(Parcel in) { return new OuterParcelable(in); } When I