| Author |
xml to object and vice versa
|
Hendra Kurniawan
Ranch Hand
Joined: Jan 31, 2011
Posts: 239
|
|
|
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
Joined: Jul 29, 2008
Posts: 275
|
|
xstream is one of the most popular ones.
You can use it for JSON too.
|
Anrd
"One of the best things you could do is to simplify a larger application into a smaller one by reducing its process and complexity - Fowler"
|
 |
E Armitage
Ranch Hand
Joined: Mar 17, 2012
Posts: 220
|
|
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
Joined: Jan 31, 2011
Posts: 239
|
|
I'm a bit confused about this xml:
why not like this:
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
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.
|
 |
 |
|
|
subject: xml to object and vice versa
|
|
|