Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xml to object and vice versa

 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • 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
 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
xstream is one of the most popular ones.
You can use it for JSON too.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I'm a bit confused about this xml:


why not like this:
 
Paul Clapham
Sheriff
Pie
Posts: 20964
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic