unmarshalling

javax.xml.bind.UnmarshalException: unexpected element. Expected elements are (none)

前提是你 提交于 2019-11-28 16:57:39
I am getting this error, while unmarshalling a string. I have created Java files using JAXB. JAXBContext jaxbContext = JAXBContext.newInstance(DocumentType.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); // Input string posted below DocumentType dType = (DocumentType) unmarshaller.unmarshal(new StringReader("input string")); Stack trace: Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"http://ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd", local:"document"). Expected elements are (none) at com.sun.xml.internal.bind.v2.runtime

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

天涯浪子 提交于 2019-11-28 13:52:24
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/NKObQB5j4O Output: [{Name:A Description:Monotremata} {Name:B Description:} {Name:C Description:}] So in this

Golang Decoding Generic JSON Objects to One of Many Formats

拈花ヽ惹草 提交于 2019-11-28 08:49:22
I am working on a general JSON based message passing protocol in golang. What I would like to do is have a BaseMessage that has general information like Type , timestamp , etc. But at the same time I want to be able to define more specific message structures for certain types of data. For example: type Message struct { Type string `json:type` Timestamp string `json:timestamp` } type EventMessage struct { Message EventType string EventCreator string EventData interface{} } I have a set of handlers and to determine which handler should process the message I decode the JSON to the general Message

How to convert Date(ActionScript 3) to java.util.Date through a xml?

橙三吉。 提交于 2019-11-28 06:19:20
问题 I want to convert Date(ActionScript 3) to java.util.Date through a xml. First, write a user defined ActionScript class like this. public class User { public function User() { userDate = new Date(); } public var id:String = null; public var password:String = null; public var userDate:Date = null; } Second, create its instance and set each of values, so it converts ActionScript class to a xml for using XMLEncoder having its schema file. This is the result xml, and send this xml to a server for

Jaxb: How to replace a class/binding in given object tree while unmarshalling

て烟熏妆下的殇ゞ 提交于 2019-11-28 05:55:33
问题 I have a given set of classes to unmarshall a xml into an object tree. Now I get a extended xml and want to replace one class in the object tree with an extended version. XML file <?xml version="1.0" encoding="UTF-8"?> <RootNode_001> <systemId>on the 4</systemId> <systemName>give me some more</systemName> <person> <firstname>James</firstname> <lastname>Brown</lastname> <address> <street>Funky</street> <city>Town</city> <type>HOME</type> <!-- this is the new field --> </address> </person> <

Golang marshal dynamic xml element name

半世苍凉 提交于 2019-11-28 05:45:35
问题 The xml file consists of two elements. Those elements have the same structure except for one element name. I tried to set a value to the XMLName property, but that didn't work. Xml: <!-- first element --> <PERSON> <ELEM1>...</ELEM1> <ELEM2>...</ELEM2> <ELEM3>...</ELEM3> <ELEM4>...</ELEM4> </PERSON> <!-- second element --> <SENDER> <ELEM1>...</ELEM1> <ELEM2>...</ELEM2> <ELEM3>...</ELEM3> <ELEM4>...</ELEM4> </SENDER> Is it possible to define a struct such that the element name is dynamic? type

Not able to extract only selected Tag values using Jaxb in Java

二次信任 提交于 2019-11-28 05:04:41
问题 I've a very big XML string. Im posting here only part of the XML object. I'm trying to convert this XML to Java object. My first question is, should I need to create Java object of total XML tag values or can I have create the Java object of only selected inner XML objects? Please find my XML string. <DATAPACKET REQUEST-ID = "2"> <HEADER> <RESPONSE-TYPE CODE="1" DESCRIPTION="Response DataPacket"/> <SEARCH-RESULT-LIST> <SEARCH-RESULT-ITEM> <NAME MATCHED="TRUE"/> </SEARCH-RESULT-ITEM> </SEARCH

Getting java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object

青春壹個敷衍的年華 提交于 2019-11-28 03:45:33
问题 I am new to RMI technology. When I am running the rmi client program, I am getting the exception : java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object. I am using jdk1.5 The argument of the remote method is the Serialized object. These are the server code... This is the Remote Interface package interfacepackage; import java.rmi.Remote; import java.rmi.RemoteException; public interface ServerInterface extends Remote{ public void getOrder(Order order)

Can not unmarshall the SOAP response

↘锁芯ラ 提交于 2019-11-28 01:43:25
问题 I could send a request and receive the response but I can not parse the response. It returns the following error: Local Name:Body error is here java.lang.NullPointerException at com.ticketmaster.ticketmaster.TicketMaster.Search(TicketMaster.java:119) at com.ticketmaster.ticketmaster.App.main(App.java:12) Code SOAPMessage response = connection.call(message, endpoint); connection.close(); SOAPMessage sm = response; SOAPBody sb = response.getSOAPBody(); System.err.println("Node Name:" + sb

JAXB: how to make JAXB NOT to unmarshal empty string to 0

半腔热情 提交于 2019-11-28 00:33:13
问题 I have a DTO class with a field such as: @XmlAttribute @NotNull private Integer number = null; I'm trying to unmarshal xml such as ... number="" ... I need the nuber field to stay null, so that a validation exception would be thrown. Instead JAXB unmarshals it as 0. How can I make it to behave correctly ? 回答1: Arguable, it is behaving correctly. number="" does not mean null, it's an empty String, and JAXB is having to try and handle that correctly, and it decides that the closest thing to