• Post Reply Bookmark Topic Watch Topic
  • New Topic

XML into POJO  RSS feed

 
Richard Butterwood
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the best way to get XML into a POJO? This POJO will then be serialized and transported to a different machine. I need something lightweight. XML Beans looks like a lot of work for what I want.

Thanks.
 
Richard Butterwood
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I should have mentioned this XML file will be received via HttpURLConnection. I don't want to save the file out to the operating system just to read back in again.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can you describe your problem a bit more? You can read the response from your HttpURLCOnnection, build a String and put that in any object you want to serialize. Is it more complicated than that?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't want to save the file out to the operating system just to read back in again.

That is not necessary, XML parsers can work with just about any character stream. Look at the org.xml.sax.InputSource class.
Bill
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Richard Butterwood:
What is the best way to get XML into a POJO? This POJO will then be serialized and transported to a different machine. I need something lightweight. XML Beans looks like a lot of work for what I want.


I may have been the person who recommended XMLBeans in another thread.
you should play around with them a bit before concluding that they are
"a lot of work". It take one line, for instances, to parse XML and create a bean:

On the other hand, these bean objects are not Serializable, because that
is not what they're about. They are lightweight facade objects backed by
the XML DOM tree.

In any case, if you are transporting data to another machine, isn't that
a good opportunity to use XML itself? Why use Java serialization for that?
 
Richard Butterwood
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the tips.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!