• Post Reply Bookmark Topic Watch Topic
  • New Topic

Limiting XML serialization

 
Todd Farmer
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am starting with Apache AXIS, and I'm having trouble returning complex objects as return values. I am wanting to return just a User object, but it appears that when the User object is serialized, the object tree is being walked and serialized with it. How can I control this? For instance, a User is assocated with a Company, and a Company has Products. I really just want to return the User, not the Company, and certainly not the Products.

Thanks!
 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not aware of a way to do this - but then I've never *really* looked. I have a suspicion it's not possible with Axis at present, but with the next generation of declarative Web service toolkits (@WebService declarations etc), maybe it will be. That last bit is pure speculation, mind.

The way I usually work around this is to create a new User (or whatever) POJO specifically for the Web service, and do a manual mapping between the types on the used-everywhere User and the one for the Web service only. This is a pain in the butt, but it's the only reasonable solution I know of.

Aside from allowing me to control exactly which attributes are sent, this has another advantage of allowing custom mappings for types used within the bulk of the application. For example, I have a load of typesafe enums (e.g, Colour - Colour.BLACK...) that I can map to String-types to be sent over a Web service. I don't know of a mapping tool that could automatically serialise enums the way I want to. I hide the ugliness of all this behind an interface, to keep the mess related to using Web services as localised as possible.

Also, if you are using the WSDL as the primary specification for your Web service interface (and so generating a Java binding off the WSDL, not the other way round), then you're essentially forced into this path: the WSDL-tool-generated POJOs for Users etc are not adequate for using in the entire application! (My preference is _always_ to use the WSDL as the primary specification - it gives you much more control over your interface...)

Sorry I can't help...I'll be interested if others know more than this.

Cheers,


-Tim
 
Todd Farmer
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Tim. I appreciate your response.

I tried declaring the Company property transient, but that didn't have any impact. I'm wondering about subclassing the User class and making the getter/setter methods private.

It sure would be great if there was a way to declaratively control which nodes of an object graph get serialized. It seems to make for a lot more work and implementation-specific artifacts without that control.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!