unmarshalling

Add SubType information at runtime using Jackson for polymorphism

强颜欢笑 提交于 2019-12-10 12:53:49
问题 I am using Jackson to unmarshal polymorphic types from JSON. I am using the @JsonTypeInfo , @JsonSubTypes , and @JsonTypeName annotations similar to Example 4 in this post. My question is, say now I need someone else to extend my code and add a 3rd class: public class Duck extends Animal outside of the original code base. How can I (or the others) add the SubType information without modifying the source code (annotation) of the public abstract Animal class ? UPDATE: I am forced to use

Jaxb Unmarshall with an unknown @XmlRootElement

╄→гoц情女王★ 提交于 2019-12-10 10:09:08
问题 I cannot achieve to unmarshall an XML without knowing the root element. eg. <foo> <bar/> </foo> or <bar> <bar/> </bar> etc... I want to map the unmarshalling result on a class like : // @XmlRootElement ?? public class Container implements Serializable { private Bar bar; } I am always required to fix the @XmlRootElement . I searched how to set the @XmlRootElement at runtime without success. Any idea? I am in Spring Batch context and I can use the unmarshaller of my choice. Note : I cannot use

How to invoke JAXB XMLAdapter directly

断了今生、忘了曾经 提交于 2019-12-10 09:52:42
问题 I am falling foul of the limitaion of jaxb's XMLAdapters when trying to unmarshal a root object directly, without it being a field in another object, and therefore bypassing the @XmlJavaTypeAdapter I'd rather not wrap my objects because this will change the xml that will be serialized in our database. And it sounds like it's possible to call the XMLAdapter directly, going by these answers elsewhere: [1] http://www.coderanch.com/t/505457/XML/jaxb-xmladapter-rootElement [2] http://markmail.org

JAXB unmarshal validation throws cvc-elt.1: Cannot find the declaration of element error

房东的猫 提交于 2019-12-10 04:35:47
问题 I'm kind of new to JAXB and validation, and have spent several hours trying to figure out this problem to no avail. I've created a simple JAXB unmarshaller sample to parse an XML file. I have created an appropriate XSD file as well, but the validator keeps complaining that it is unable to find the declaration of an element. I think it may be related to namespace issues, but I've tried everything I can think of and still can't seem to resolve the error. As far as I can tell, my XSD and XML are

How do I call this c function in c# (unmarshalling return struct)?

会有一股神秘感。 提交于 2019-12-10 02:58:44
问题 I want to use c# interop to call a function from a dll written in c. I have the header files. Take a look at this: enum CTMBeginTransactionError { CTM_BEGIN_TRX_SUCCESS = 0, CTM_BEGIN_TRX_ERROR_ALREADY_IN_PROGRESS, CTM_BEGIN_TRX_ERROR_NOT_CONNECTED }; #pragma pack(push) #pragma pack(1) struct CTMBeginTransactionResult { char * szTransactionID; enum CTMBeginTransactionError error; }; struct CTMBeginTransactionResult ctm_begin_customer_transaction(const char * szTransactionID); How do I call

Golang json Unmarshal “unexpected end of JSON input”

核能气质少年 提交于 2019-12-10 01:12:09
问题 I am working on some code to parse the JSON data from an HTTP response. The code I have looks something like this: type ResultStruct struct { result []map[string]string } var jsonData ResultStruct err = json.Unmarshal(respBytes, &jsonData) The json in the respBytes variable looks like this: { "result": [ { "id": "ID 1" }, { "id": "ID 2" } ] } However, err is not nil. When I print it out it says unexpected end of JSON input . What is causing this? The JSON seems to valid. Does this error have

Unmarshal error in JAXB

[亡魂溺海] 提交于 2019-12-09 20:43:01
问题 This is the generated code for "PersonType" class. package demo; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "PersonType", propOrder = { "name", "address" }) public class PersonType { @XmlElement(name = "Name", required = true) protected String name;

Marshalling/unmarshalling XML in Scala

自作多情 提交于 2019-12-09 02:24:59
问题 I am looking at various approaches for marshalling/unmarshalling data between Scala and XML, and I'm interested in getting community feedback (preferably grounded in first-hand knowledge/experience). We're currently using JAXB, which is fine, but I'm hoping for a pure Scala solution. I'm considering the following approaches: Use Scala's built-in XML facilities : Scala->XML would be easy, but my guess is that the other direction would be fairly painful. On the other hand, this approach

Help troubleshooting JAXB unmarshalling NPE

亡梦爱人 提交于 2019-12-08 19:11:52
问题 I am working with an API which I do not have control on, which returns XMLs. Basically I have directory object that can contain multiple directory and file objects which are not wrapped by any tag, among few other primitive fields. file object contains few primitive fields, and 2 lists which are wrapped by tPathList and oPathList tags. Below is an example of such XML: <hwreply> <result>1</result> <directory> <file> <created>DATE</created> <modified>DATE</modified> <name>STRING</name> <size

How to refactor XSD so that unmarshalling does not return JAXBElement

心已入冬 提交于 2019-12-08 16:07:44
问题 I have the following schema: <xsd:schema xmlns:bar="http://www.foo.org/bar" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:annox="http://annox.dev.java.net" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" targetNamespace="http://www.foo.org/bar" jaxb:extensionBindingPrefixes="annox" jaxb:version="2.1" elementFormDefault="qualified"> <xsd:element name="unit" type="bar:unit" /> <xsd:complexType name="unit"> <xsd:annotation> <xsd:appinfo> <annox:annotate>@javax.xml.bind.annotation