Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding JAXB 1.3

 
Jobin Mathew
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I use JAXB to convert Java class to xml without using the classes generated by schema compiler.

ie, I manually created the bean classes and i want to convert it to xml using JAXB. Is there any way to do that?


Thanks In Advance.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the classes follow JavaBeans conventions then you don't need JAXB. Have a look at the java.beans.XMLEncoder/XMLDecoder classes.
 
Jobin Mathew
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will it support Array of Objects.

Lets say

private Students[] student; which contains array of student object.
 
Jobin Mathew
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also it is not preparing xml in a goo format.

The below xml is the one i got for a bean with 2 attributes id and name.

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_04" class="java.beans.XMLDecoder">
<object class="test.mainpgms.A">
<void property="id">
<string>Id</string>
</void>
<void property="name">
<string>Name</string>
</void>
</object>
</java>
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the format of the XML matters (why?) you could use an XSLT transformation to transform it into any format you like.

If you're looking for more options, a library like XStream is probably more up your alley.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic