« Return to Thread: Re: Problem with circular relationship when using JAXWS

Re: Problem with circular relationship when using JAXWS

by metro-3 :: Rate this Message:

Reply to Author | View in Thread

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@...

 « Return to Thread: Re: Problem with circular relationship when using JAXWS