jaxb2

How do return Java List<String> Json using Jax-RS

守給你的承諾、 提交于 2019-12-01 06:53:46
I'd like know how do to a method return a JSON array of List, for example: @GET @Produces("application/json") public List<String> aMethod(){ return Array.asList("text1", "text2", "text3"); } I'd want to know, how do to receive a List argument type in my method, for example @PUT @Consumes("application/json") void otherMethod(List<String>){ // do something ; } I've read about JaxbContext, I understanding how it can help me. With JAXB there are two type's of List supported. The first is a List of elements, the second a delimited string (a "normal" XML value or attribute, which is parsed into a

Need help in formatting JAXB output

醉酒当歌 提交于 2019-12-01 06:37:42
问题 I have some objects let's say two, A and B. These objects from the same class. I need to marshal these objects using JAXB and the output XML should be in this form: <Root> <A> <ID> an id </ID> </A> <B> <ID> an id </ID> </B> </Root> <!-- Then all A and B attributes must be listed !--> <A> <ID> an id </ID> <attribute1> value </attribute1> <attribute2> value </attribute2> </A> <B> <ID> an id </ID> <attribute1> value </attribute1> <attribute2> value </attribute2> </B> How to generate this format

Using an adapter to marshal a class to a root element with MOXy or any other JAXB implementation

狂风中的少年 提交于 2019-12-01 05:34:16
问题 I have a class which extends the CompositeConfiguration class from Apache Commons Configuration. I am trying to marshal it to XML using MOXy. I have created an XML adapter that converts the configuration to a list of simple name/value objects. I have tried using a number of variations on what I have below but am still stymied. I can see my adapter class being loaded and instantiated when I create the JAXB context but it is never called when I marshal the configuration object. Looking at the

JAXB Unmarshalling @XmlAnyElement

纵饮孤独 提交于 2019-12-01 05:16:24
I have created three JAXB class : Home , Person , Animal . Java Class Home have variable List<Object> any that may contain Person and/or Animal instance . public class Home { @XmlAnyElement(lax = true) protected List<Object> any; //setter getter also implemented } @XmlRootElement(name = "Person") // Edited public class Person { protected String name; //setter getter also implemented } @XmlRootElement(name = "Animal") // Edited public class Animal { protected String name; //setter getter also implemented } /* After Unmarshalling */ Home home ; for(Object obj : home .getAny()){ if(obj instanceof

How do return Java List<String> Json using Jax-RS

非 Y 不嫁゛ 提交于 2019-12-01 04:56:38
问题 I'd like know how do to a method return a JSON array of List, for example: @GET @Produces("application/json") public List<String> aMethod(){ return Array.asList("text1", "text2", "text3"); } I'd want to know, how do to receive a List argument type in my method, for example @PUT @Consumes("application/json") void otherMethod(List<String>){ // do something ; } I've read about JaxbContext, I understanding how it can help me. 回答1: With JAXB there are two type's of List supported. The first is a

JAXB Unmarshalling @XmlAnyElement

倾然丶 夕夏残阳落幕 提交于 2019-12-01 02:23:38
问题 I have created three JAXB class : Home , Person , Animal . Java Class Home have variable List<Object> any that may contain Person and/or Animal instance . public class Home { @XmlAnyElement(lax = true) protected List<Object> any; //setter getter also implemented } @XmlRootElement(name = "Person") // Edited public class Person { protected String name; //setter getter also implemented } @XmlRootElement(name = "Animal") // Edited public class Animal { protected String name; //setter getter also

Jaxb: How do I generate ObjectFactory class?

放肆的年华 提交于 2019-11-30 20:00:41
I'm using Java 6, JaxB 2 and SpringSource Tool Suite (same as Eclipse). I had a couple of Java classes I wrote, from which I used JaxB to generate an XML schema. However, I'm noticing in order to use JaxB's ability to generate an XML document from Java objects, I need an ObjectFactory. final Marshaller marshaller = jaxbContext.createMarshaller(); // Here is where I don't have an ObjectFactory defined final JAXBElement<WebLeads> webLeadsElement = (new ObjectFactory()).createWebLeads(webLeadsJavaObj); How can I generate an ObjectFactory without blowing away the classes I already have now? UPDATE

Is there a JAXB Plugin which generates Builders?

爱⌒轻易说出口 提交于 2019-11-30 18:19:54
Are you aware of any good JAXB Plugin which generated Builder pattern classes for the generated JAXB classes? Composing domain using JAXB generated classes is really nasty. I saw a plugin someone wrote back in 2010 but it doesn't use the newest maven plugin jaxb2-maven-plugin, and it also requires you to specify bindings for each schema type which is not robust. Yes, there is now a plugin to generate fluent builders for JAXB-generated classes. There is a github project on https://github.com/mklemm/jaxb2-rich-contract-plugin It contains a couple of useful JAXB plugins. You can download source

Why has AnnotationReader been removed from JAXB reference implementation?

主宰稳场 提交于 2019-11-30 16:38:15
问题 The class com.sun.xml.bind.v2.model.annotation.AnnotationReader was part of jaxb-impl 2.1.6, but has been removed in 2.1.7. Does anybody know why? 回答1: JAXB artifacts were restructured in 2.2.11 so a few classes were moved between jaxb-runtime and jaxb-core . AnnotationReader is not the only one. The main reason is (probably) the mavenisation which required rearranging a few classes due to dependency structure. Unfortunately the old artifacts com.sun.xml.bind:* has a bit wrong dependency

Unmarshalling nested list of xml items using JAXB

依然范特西╮ 提交于 2019-11-30 16:00:19
I've got such xml construction which I need to convert into java objects using JAXB: <elements> <elemet> <type></type> <property1></property1> <property2></property2> <items> <item> <id></id> <name></name> </item> ... <item> <id></id> <name></name> </item> </items> </element> </elements> I should convert this construction not into element with nested list of items but into several elements one for every item. Here is example of Element class: class Element { Integer type; String property1; String property2; Integer itemId; String itemName; } I want to get list of them after unmarshalling. Type