unmarshalling

Unmarshalling XML with JAXB without unescaping characters

。_饼干妹妹 提交于 2019-12-01 06:46:36
问题 imagine following situation: we receive a xml file from some external tool. Lately within this xml, there can be some escaped charakters in nodenames or within their richcontent tag, like in the following example (simplyfied): <map> <node TEXT="Project"> <node TEXT="ää"> <richcontent TYPE="NOTE"><html> <head> </head> <body> <p> I am a Note for Node ää! </p> </body> </html> </richcontent> </node> </node> </map> After unmarshalling the file with JAXB those escaped charakters get unescaped.

How to bind a xml element into an object member variable?

泄露秘密 提交于 2019-12-01 06:44:35
I'm trying to unmarshal an xml to an object using moxy.Below is the sample of the xml. <root> <name> <firstname>value</firstname> </name> <address>value of address</address> </root> And below is the class I'm trying to map. import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import org.eclipse.persistence.oxm.annotations.XmlPath; @XmlRootElement(name="root") @XmlAccessorType(XmlAccessType.FIELD) public class Response { @XmlPath("name/firstname/text()")

JAXB mapping elements with “unknown” name

蓝咒 提交于 2019-12-01 06:32:46
I have an XML which is out of my control on how it is generated. I want to create an object out of it by unmarshaling it to a class written by hand by me. One snippet of its structure looks like: <categories> <key_0>aaa</key_0> <key_1>bbb</key_1> <key_2>ccc</key_2> </categories> How can I handle such cases? Of course the element count of is variable. If you use the following object model then each of the unmapped key_# elements will be kept as an instance of org.w3c.dom.Element: import java.util.List; import javax.xml.bind.annotation.XmlAnyElement; import javax.xml.bind.annotation

How to bind a xml element into an object member variable?

北城以北 提交于 2019-12-01 05:03:20
问题 I'm trying to unmarshal an xml to an object using moxy.Below is the sample of the xml. <root> <name> <firstname>value</firstname> </name> <address>value of address</address> </root> And below is the class I'm trying to map. import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import org.eclipse.persistence.oxm.annotations.XmlPath; @XmlRootElement(name=

JAXB Avoid saving default values

删除回忆录丶 提交于 2019-12-01 04:24:07
问题 Is there any way to make JAXB not save fields which values are the default values specified in the @Element annotations, and then make set the value to it when loading elements from XML that are null or empties? An example: class Example { @XmlElement(defaultValue="default1") String prop1; } Example example = new Example(); example.setProp1("default1"); jaxbMarshaller.marshal(example, aFile); Should generate: <example/> And when loading Example example = (Example) jaxbUnMarshaller.unmarshal

What is the ObjectFactory role during JAXB-Unmarshalling?

百般思念 提交于 2019-12-01 03:37:38
I'm using JAXB 2.2.2 to parse a simple XML-REST stream. This is the piece of code: JAXBContext jc = JAXBContext.newInstance( "com.example.entities" ); Unmarshaller u = jc.createUnmarshaller(); r = (Response )u.unmarshal( inputStream ); ObjectFactory class: @XmlRegistry public class ObjectFactory { public Response createRsp() { return new Response(); } } Response class: @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name="rsp") @XmlType public class Response { ... } The "com.example.entities" must contain the ObjectFactory class or jaxb.index. I would like to use the ObjectFactory class

Marshalling/unmarshalling XML in Scala

て烟熏妆下的殇ゞ 提交于 2019-12-01 02:35:41
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 supports arbitrary translation logic. Data binding : scalaxb seems to be somewhat immature at the moment and

Custom UnmarshalYAML, how to implement Unmarshaler interface on custom type

有些话、适合烂在心里 提交于 2019-12-01 01:58:52
问题 I parse a .yaml file and need to unmarshal one of its properties in a custom manner. I am using the "gopkg.in/yaml.v2" package. The property in question is stored like this in my .yaml file: endPointNumberSequences: AD1: [ 0, 10, 14, 1, 11, 2, 100, 101, 12 ] So it is basically a map[string][]uint16 kind of type. But I need map[string]EpnSeq where EpnSeq is defined as: type EpnSeq map[uint16]uint16 My struct: type CitConfig struct { // lots of other properties // ... EndPointNumberSequences

What is the ObjectFactory role during JAXB-Unmarshalling?

余生长醉 提交于 2019-11-30 23:55:51
问题 I'm using JAXB 2.2.2 to parse a simple XML-REST stream. This is the piece of code: JAXBContext jc = JAXBContext.newInstance( "com.example.entities" ); Unmarshaller u = jc.createUnmarshaller(); r = (Response )u.unmarshal( inputStream ); ObjectFactory class: @XmlRegistry public class ObjectFactory { public Response createRsp() { return new Response(); } } Response class: @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name="rsp") @XmlType public class Response { ... } The "com.example

Jersey: Consume all POST data into one object

会有一股神秘感。 提交于 2019-11-30 22:10:12
I am using Jersey 1.8 in my application. I am trying to consume POST data at the server. The data is of the type application/x-www-form-urlencoded . Is there a method to get all the data in one object, maybe a Map<String, Object> . I ran into Jersey's @Consumes(MediaType.APPLICATION_FORM_URLENCODED) . But using this would require me to use @FormParam , which can be tedious if the number of parameters are huge. Or maybe one way is this: @POST @Path("/urienodedeample") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON) public Response uriEncodedExample(String