*
The moose likes Java in General and the fly likes Pattern for marshalling, unmarshalling objects to multiple formats Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Pattern for marshalling, unmarshalling objects to multiple formats" Watch "Pattern for marshalling, unmarshalling objects to multiple formats" New topic
Author

Pattern for marshalling, unmarshalling objects to multiple formats

Nathan England
Greenhorn

Joined: Jul 13, 2009
Posts: 20
Hello, I have a question regarding what pattern or approach to use in Java for the following scenario:

In the "real world" I'm using a web API that accepts a REST query, an XML string, or a SOAP message.
However, the question isn't about the service but rather which pattern do I use to marshall a plain Java object into XML, SOAP, JSON, or a URL REST query key/value pairs.
Theoretically, I have just a given POJO, but I want to convert that into different forms (XML, REST style map, SOAP, JSON).

I cannot change the code for the POJO (but they are annotated where I can use JAXB, at least for the XML part). But I need to take a POJO and be able to generate all different formats without changing the base POJO.

Which design pattern or patterns should I investigate to accomplish this task?
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1035
    
  10

I suspect you need the visitor pattern - http://en.wikipedia.org/wiki/Visitor_pattern .
Nathan England
Greenhorn

Joined: Jul 13, 2009
Posts: 20
Thanks for the quick response! I'll check that out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pattern for marshalling, unmarshalling objects to multiple formats
 
Similar Threads
Retrieving a Java Object from AJAX Respnse
Webservices with protocal buffers
What is Web Service?
Build a RESTful web service
get the value from JSON String(SOAP content)