On 02/02/13 20:01, fahman_dude wrote:
Hi,

I have a question on marshalling mechanics of @XmlIDREF. I have these two
classes Assignment and Project and are able to marshal and unmarshal them
with CXF default configuration just nicely.

  public class Assignment {
     Project project;
     int position;

     @XmlIDREF
     @XmlAttribute
     public Project getProject() {
         return project;
     }

     public int getPosition() {
         return position;
     }
  }

  public class Project {

     String id;

     @XmlID
     public String getId() {
         return id;
     }
  }

JSON looks like this:

   {"assignment":{"@project":"123","position":567}},
{"project":{"id":"123",...}}

But, the question is - how do I control how the @XmlIDREF is represented in
marshaled JSON message. Currently it is marshalled as "@project":"123". What
if we would like to marshall it as "$project":"123"? So that it look like
this:

     {"assignment":{"$project":"123","position":567}},
{"project":{"id":"123",...}}

Jettison can use "$" but only to mark the text coming in as part of the mixed content, it won't know that a given property such as "project" needs to be marked with "$".

Have a look at this code:
https://github.com/Talend/tesb-rt-se/blob/master/examples/cxf/jaxrs-advanced/common/src/main/java/common/advanced/Person.java

(at the very bottom), I copied it from one of StackOverflow pages - can not find right now - you can customize I guess how the reference is represented, so in you case you may try to represent it say as "projectIdRef" for the JSON consumer to figure out what it represents

HTH, Sergey



Thanks
Reinis



--
View this message in context: 
http://cxf.547215.n5.nabble.com/JSON-marshalling-of-XmlIDRef-tp5722641.html
Sent from the cxf-user mailing list archive at Nabble.com.


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to