unmarshalling

JAXB: unmarshalling xml with multiple names for the same element

可紊 提交于 2019-11-27 23:44:58
问题 I figure this will be easy for someone who really understands JAXB binding files... Basic Question How do you configure JAXB to unmarshal multiple elements into the same class? Note: I want to avoid adding another dependency to my project (like MOXy). Ideally, this can be accomplished with annotations or a custom bindings file. Background I have an XML document that contains lots of variations of the same element--each with the exact same properties. Using my example below, all I care about

How to fix Unmarshalling unknown type code XXX at offset YYY in Android?

北城以北 提交于 2019-11-27 20:05:24
I'm having app crash on resume because of Unmarshalling exception. I've checked all the Serializables have constructor with no parameters and even checked all the serializables using ObjectStream (save to file and load from file). How can i understand actual class type for parcelable offset that cause exception: Parcel android.os.Parcel@42209460: Unmarshalling unknown type code 2131165303 at offset 3748 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2080) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2105) at android.app.ActivityThread.access

How to unmarshall an array of different types correctly?

心已入冬 提交于 2019-11-27 17:40:48
问题 As long as I have key-value pairs unmarshalling is pretty straight forward but how would I unmarshall an array of different types in different order? The single elements are well defined and known but the order is not. I can not come up with a beautiful solution. Would I try and error over all elements? Is there some kind of union type that could do that for me? playground version package main import ( "encoding/json" "fmt" ) var my_json string = `{ "an_array":[ "with_a string", { "and":"some

JAXB - Ignore element

自作多情 提交于 2019-11-27 14:57:00
Is there any way to just ignore an element from Jaxb parsing? I have a large XML file, and if I could ignore one of the large, complex elements, then it would probably parse a lot quicker. It would be even better if it could not even validate the element contents at all and parse the rest of the document even if that element is not correct. ex:this should only generate Foo.element1 and Foo.element2 <foo> <element1>I want this</element1> <element2>And this</element2> <bar> <a>ALL of bar should be ignored</a> <b>this also should be ignored</b> <c> <x>a lot of C that take time to process</x> </c>

Unmarshalling generic list with JAXB

≡放荡痞女 提交于 2019-11-27 14:07:51
问题 I've a service that returns this XML: <?xml version="1.0" encoding="UTF-8"?> <response> <status>success</status> <result> <project> <id>id1</id> <owner>owner1</owner> </project> <project> <id>id2</id> <owner>owner2</owner> </project> </result> or <?xml version="1.0" encoding="UTF-8"?> <response> <status>success</status> <result> <user> <id>id1</id> <name>name1</name> </user> <user> <id>id2</id> <name>name2</name> </user> </result> I want to unmarshall the retrieved XML using these classes:

How can I have JAXB call a method after it has completed unmarshalling an XML file into an object?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 13:58:07
I am using JAXB to unmarshall an XML file into a Java object -- standard stuff. Once JAXB has completed this, I'd like a method to be called on the newly created object. Is there a mechanism to do this? I'd prefer the object, not an external entity, do this to keep construction in one place. Thanks. To be able to execute code after unmarshalling took place, you need an Unmarshaller-Listener However, I'm not sure, if the listener is invoked after the properties are set or before. NOTE: The listener is available since JAXB- 2.0 (JDK- 6 ) You can simple add the following method to your object

How to create java object from 'anyType' returned from service using JAXB?

风格不统一 提交于 2019-11-27 13:44:19
问题 A web service is returning an object defined by the WSDL to be: <s:complexType mixed="true"><s:sequence><s:any/></s:sequence></s:complexType> When I print out this object's class info, it comes up as: class com.sun.org.apache.xerces.internal.dom.ElementNSImpl But I need to unmarshall this object as an object of the following class: @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "info", "availability", "rateDetails", "reservation", "cancellation", "error" })

“BadParcelableException: ClassNotFoundException when unmarshalling <myclass>” while using Parcel.read method that has a ClassLoader as argument

纵然是瞬间 提交于 2019-11-27 11:12:25
Given a custom class org.example.app.MyClass implements Parcelable , I want to write a List<MyClass> to a Parcel. I did the marshalling with List<MyClass> myclassList = ... parcel.writeList(myclassList); whenever I try to unmarshall the class with List<MyClass> myclassList = new ArrayList<MyClass>(); parcel.readList(myclassList, null); there is an "BadParcelableException: ClassNotFoundException when unmarshalling org.example.app.MyClass" exception. What is wrong here? Why is the class not found? Flow Don't unmarshall a custom class (i.e. one provided by your application and not by the Android

json.Unmarshal returning blank structure

亡梦爱人 提交于 2019-11-27 09:29:35
I have a JSON blob that looks like this { "metadata":{ "id":"2377f625-619b-4e20-90af-9a6cbfb80040", "from":"2014-12-30T07:23:42.000Z", "to":"2015-01-14T05:11:51.000Z", "entryCount":801, "size":821472, "deprecated":false }, "status":[{ "node_id":"de713614-be3d-4c39-a3f8-1154957e46a6", "status":"PUBLISHED" }] } and I have a little code to transform that back into go structs type Status struct { status string node_id string } type Meta struct { to string from string id string entryCount int64 size int64 depricated bool } type Mydata struct { met meta stat []status } var realdata Mydata err1 :=

How to recognize void value and unspecified field when unmarshaling in Go?

吃可爱长大的小学妹 提交于 2019-11-27 08:09:09
问题 I would like to know if it's possible to differenciate a void value and an unspecified field value. Here is an example: var jsonBlob = []byte(`[ {"Name": "A", "Description": "Monotremata"}, {"Name": "B"}, {"Name": "C", "Description": ""} ]`) type Category struct { Name string Description string } var categories []Category err := json.Unmarshal(jsonBlob, &categories) if err != nil { fmt.Println("error:", err) } fmt.Printf("%+v", categories) Also available here: https://play.golang.org/p