• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pattern for marshalling, unmarshalling objects to multiple formats

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect you need the visitor pattern - http://en.wikipedia.org/wiki/Visitor_pattern .
 
Nathan England
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick response! I'll check that out.
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic