• 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

xml to object and vice versa

 
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any framework that automates XML to POJO and vice versa? something like jackson to convert JSON to object. Does Axis2 have thi capability or does java already have built-in implementation for this? thanks
 
Ranch Foreman
Posts: 275
jQuery Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
xstream is one of the most popular ones.
You can use it for JSON too.
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hendra Kurniawan wrote:Is there any framework that automates XML to POJO and vice versa? something like jackson to convert JSON to object. Does Axis2 have thi capability or does java already have built-in implementation for this? thanks


JAXB is now part of the standard API.
You can just use JAXB.marshal and JAXB.unmarshal methods

http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/JAXB.html
 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a bit confused about this xml:


why not like this:
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not, indeed? Those are two ways of describing the same data. But I don't see where the confusion is, there's nothing wrong with having two or more ways of doing the same thing.

However that's not the end of the story. There are reasons why you would use attributes and there are reasons why you would use elements. The most obvious is that an element can't have two attributes with the same name, but it can have two child elements with the same name. And from a design point of view, using an attribute signals that there can't be duplicates. The debate goes much farther than that, though, I suggest you google for xml element versus attribute if you really want to get into that.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic