Re: Problem with circular relationship when using JAXWS

View: New views
3 Messages — Rating Filter:   Alert me  

Re: Problem with circular relationship when using JAXWS

by metro-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

There is another potential solution for this issue:

Assuming:

Parent.class contains a list of Child.class with backreferences to Parent

You can use an XmlAdapter (using @XmlJavaTypeAdapter(ParentAdapter.class)
 Child.getParent())

This allows you to modify the value of Child.getParent() that is marshalled into XML containing the parent Id. On return trip/unmarshalling, the parent field will be populated with a new object containing only "id" -- it prevents nullpointers, but might be somewhat misleading... null may be preferred, in which case, use the @XmlTransient solution.


import javax.xml.bind.annotation.adapters.XmlAdapter;

public class ParentAdapter extends XmlAdapter<Long, Feature>
{
    @Override
    public Long marshal(Feature feature) throws Exception
    {
        return feature.getId();
    }

    @Override
    public Feature unmarshal(Long id) throws Exception
    {
        return new Feature().setId(id);
    }

}
[Message sent by forum member 'lincolnbaxter' (lincolnbaxter)]

http://forums.java.net/jive/thread.jspa?messageID=354973

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem with circular relationship when using JAXWS

by metro-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I did not understand it.
Appreciate a little bit more explanation with an example

Thanks,
Rahul
[Message sent by forum member 'rahul_juneja' (rahul_juneja)]

http://forums.java.net/jive/thread.jspa?messageID=354995

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem with circular relationship when using JAXWS

by Glen Mazza :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

https://jaxb.dev.java.net/guide/Mapping_cyclic_references_to_XML.html ?

metro-3 wrote:
I did not understand it.
Appreciate a little bit more explanation with an example

Thanks,
Rahul