So I have been able to code my service using JAX-RS and I get propery XML back and can send it. All peachy.

Now, once the XML is on the client side, I need to reconstruct the objects that were transferred.

           JAXBContext jc = JAXBContext.newInstance( User.class );
           Unmarshaller u = jc.createUnmarshaller();
User lUser = (User)u.unmarshal(new ByteArrayInputStream( s.getBytes() ) );
           System.out.println(lUser);


Ok there too. So.

Then it got me thinking... That unmarshalled object is using the original class definition that was marshalled before (this is inside a unittest, so both the server and the unittest access the same User class). But I do not want my client to use my original class; these are fairly complex classes which are interlaced with JPA code. For example methods like "getGroups()" which required new entities which may not have been send as XML. What I really would require is a shell-class that only contains the stuff that JAXB has (un)marshalled, but is "XML compatible" with the actual business class.

I know that JAXB can create Java classes based on an XML-Schema, but I do not have an XML schema, only annotated classes, and I do not like to have duplication.

1. Is there a way to convert annotated classes to an XML-schema so that can be used to generated shell-classes?

2. does anyone have a suggestion on how else to handle this don't-want-my-domain-objects-made-available-to-the-client?

Tom

Reply via email to