users@jersey.java.net

Re: [Jersey] How to add XML node to existing JAXB annotatied class?

From: Daniel Manzke <daniel.manzke_at_googlemail.com>
Date: Fri, 13 Feb 2009 11:36:48 +0100

Just an Idea:
Another solution could be to have a List annotated with XmlAnyElement. So
your are free to add more objects. But for that you have to provided this
list in your object. Maybe mix Paul's and my solution and you have an object
which is ready for future. :)

(we are using this approach for webdav - because the properties can be
extended without extending the SPEC)


Best Regards from Germany,
Daniel


2009/2/13 Paul Sandoz <Paul.Sandoz_at_sun.com>

>
> On Feb 13, 2009, at 6:38 AM, bndi wrote:
>
> Hi all.
>>
>> Product.java :
>> ---------------------------------------
>> @XmlAccessorType(XmlAccessType.FIELD)
>> @XmlRootElement
>> public class Product {
>> private int code;
>> private String name;
>> }
>> ---------------------------------------
>>
>> ProductResource.java :
>> ---------------------------------------
>> public class ProductResource {
>> @Path("info/")
>> public Response getProductInfo() {
>> Product p = new Product();
>> p.setCode(1234);
>> p.setName("test");
>> // how to add XML node this point? e.g. "total=1000"
>> return ResponseImpl.ok(p).build();
>> }
>> }
>> ---------------------------------------
>>
>> expected result :
>> ---------------------------------------
>> <product>
>> <code>1234</code>
>> <name>test</name>
>> <total>1000</total>
>> </product>
>> ---------------------------------------
>>
>> how to do this?
>>
>> You need to modify your Product class to have a field called "total".
>
> If you cannot modify that class but can extend from it then i think you can
> do:
>
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlRootElement
> public class ExtendedProduct extends Product {
> private int total;
> }
>
>
>
> ==========================================
>> https://jersey.dev.java.net/servlets/ReadMsg?list=users&msgNo=3785
>>
>> Paul. wrote.
>> > But. given that the client states what the function should be in the
>> > query parameter why can't it do the work itself and wrap the JSON
>> > around the function? why it is necessary to do this on the server side?
>>
>> I'm provide json format data to OpenAPI service.
>> but what if problem is cross domain security error. e.g) my domain is '
>> aaa.com' and user's domain is 'bbb.com'
>> therefore wrap javascript callback function name to json message body.
>> e.g) zzz({"code":"12312","name":"yyy"})
>> and using below javascript to avoid cross domain problem.
>> ------------------------------------------
>> aaa : function()
>> {
>> obj.s = document.createElement('script');
>> obj.s.type ='text/javascript';
>> obj.s.charset ='utf-8';
>> obj.s.src = 'http://aaa.com?callback=obj.bbb' +
>> encodeURI(obj.q.value);
>> }
>> },
>>
>> bbb : function(z)
>> {
>> // TODO
>> },
>> ------------------------------------------
>>
>>
> I see. Jakub has added JSONP support in 1.0.2:
>
>
> https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/jersey/com/sun/jersey/api/json/JSONWithPadding.html
>
> http://download.java.net/maven/2/com/sun/jersey/samples/jsonp/1.0.2/jsonp-1.0.2-project.zip
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>


-- 
Mit freundlichen Grüßen
Daniel Manzke