jaxb2

JAXB java.util.Map binding

我怕爱的太早我们不能终老 提交于 2019-12-30 04:02:04
问题 I have a Json response which looks like the following: { "data": [ { "param1": "value1", "param2": "value2", . . . "paramN": "valueN" } ] } I don't know the name and the number of the parameters. So, I need and want to bind all these parameters to a java.util.Map field consisting of <"paramX", "valueX"> tuples. To do this, I tried the following code but "parametersMap" field returns null. @XmlRootElement(name="data") @XmlAccessorType(XmlAccessType.FIELD) public class Parameters { @XmlElement

why jaxb adapter annotation is not added to the proxy classes

本小妞迷上赌 提交于 2019-12-29 07:21:12
问题 My XSD looks like this: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> ... <xs:element name="person"> <xs:complexType> ... <xs:attribute name="first_name" use="optional" type="xs:string"/> </xs:complexType> </xs:element> ... </xs:schema> I can't manage to add my adapter annotation to the concrete field ( generated proxy class must have my adapter annotation). So the result should be the following : @XmlJavaTypeAdapter(value=StringAdapter.class, type

why jaxb adapter annotation is not added to the proxy classes

梦想的初衷 提交于 2019-12-29 07:21:09
问题 My XSD looks like this: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> ... <xs:element name="person"> <xs:complexType> ... <xs:attribute name="first_name" use="optional" type="xs:string"/> </xs:complexType> </xs:element> ... </xs:schema> I can't manage to add my adapter annotation to the concrete field ( generated proxy class must have my adapter annotation). So the result should be the following : @XmlJavaTypeAdapter(value=StringAdapter.class, type

JAXB use String as it is

天大地大妈咪最大 提交于 2019-12-28 06:36:10
问题 I use REST and i was wondering if i can tell jaxb to insert a string field "as-it-is" into the outgoing xml. Certainly i count unpack it before returning, but i would like to save this step. @XmlRootElement(name="unnestedResponse") public class Response{ @Insert annotation here ;-) private String alreadyXml; private int otherDate; ... } Is there a possability to tell JAXB to just use the String as it is without escapting? I want that the client does not have to parse my response and then

JAXB use String as it is

落爺英雄遲暮 提交于 2019-12-28 06:36:08
问题 I use REST and i was wondering if i can tell jaxb to insert a string field "as-it-is" into the outgoing xml. Certainly i count unpack it before returning, but i would like to save this step. @XmlRootElement(name="unnestedResponse") public class Response{ @Insert annotation here ;-) private String alreadyXml; private int otherDate; ... } Is there a possability to tell JAXB to just use the String as it is without escapting? I want that the client does not have to parse my response and then

JAXB: how to marshall map into <key>value</key>

自闭症网瘾萝莉.ら 提交于 2019-12-27 10:33:02
问题 The question is about JAXB Map marshalling - there is plenty of examples on how to marhsall a Map into a structure like follows: <map> <entry> <key> KEY </key> <value> VALUE </value> </entry> <entry> <key> KEY2 </key> <value> VALUE2 </value> </entry> <entry> ... </map> In fact, this is natively supported by JAXB. What I need, however, is the XML where key is the element name, and value is its content: <map> <key> VALUE </key> <key2> VALUE2 </key2> ... </map> I didn't succeed implementing my

How do I convert the following xml into java objects using JAXB

天涯浪子 提交于 2019-12-25 12:27:07
问题 What is the best way to convert this XML into Java objects? <entity> <customers id=2 other="data"> <customer name="john">testData1</customer> <customer name="jenny">testData2</customer> <customer name="joe">testData3</customer> <customer name="joanna">testData4</customer> </customers> </entity> Is it best to use a custom XMLAdapter with a HashMap to convert multiple xml rows of <customer> ? I'm not sure if the XMLAdapter is the proper use case for this scenario. Any ideas would be appreciated

Jaxb: How to specify a default class for an XSD element

我的未来我决定 提交于 2019-12-25 07:59:52
问题 When generating Java classes from a XSD, how can I specify that for some specific node, a specific and already existent Java class should be used instead of trying to generate one? Thank you very much. 回答1: You can use episode file to reference the existing classes. .episode files are just jaxb bindings file and has mappings between elements and java classes. a) if those existing classes are also generated from (another) xsd. use below option to first create .episode file. xjc -episode a

How do I tell the maven-jaxb2-plugin to run xjc on all .xsd files in a maven dependency?

倖福魔咒の 提交于 2019-12-25 04:28:09
问题 I'm using the maven-jaxb2-plugin and my .xsd files are in a maven dependency. The documentation shows that you specify a .xsd in a maven dependency like this <schema> <!-- Specifies a schema from the Maven artifact. --> <dependencyResource> <groupId>org.jvnet.jaxb2.maven2</groupId> <artifactId>maven-jaxb2-plugin-tests-po</artifactId> <!-- Version of the artifact. May be omitted. The plugin will then try to find the version using the dependencyManagement and dependencies of the project. -->

jaxb namespaces in each element instead of root element during marshalling

自闭症网瘾萝莉.ら 提交于 2019-12-25 03:38:29
问题 By default, jaxb 2 lists all (all possible required) namespaces in root element during marshalling: <rootElement xmlns="default_ns" xmlns:ns1="ns1" xmlns:ns2="ns2"> <ns1:element/> </rootElement> Is there a way to describe namespace in each element instead of root element ?: <rootElement xmlns="default_ns"> <element xmlns="ns1"/> </rootElement> It also solves the problem of "unnecessary namespaces", which is also important in my case. Any suggestions appreciated. 回答1: The answer is negative,