Reputation: 26262
The reading that I've done thus far on JAXB suggests that its usage is limited to serializing classes that one can annotate properly (i.e. one has the class' source).
Is there a way to use JAXB to serialize 3rd-party class (i.e. one does not have the source) using reflection?
At this point, I'm doing this manually.
Upvotes: 3
Views: 967
Reputation: 185
I'm not sure, but you might wanna look at xstream (http://x-stream.github.io/) if you just try to serialize and deserialize objects to XML and back.
Greetings -Sascha-
Upvotes: 0
Reputation: 149007
Note: I'm the EclipseLink JAXB (MOXy) lead, and a member of the JAXB 2 (JSR-222) expert group.
EclipseLink JAXB (MOXy) offers an extension that enables you to represent your metadata as XML allow which is necessary when mapping third party classes:
Sample
<?xml version="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="blog.bindingfile">
<xml-schema
namespace="http://www.example.com/customer"
element-form-default="QUALIFIED"/>
<java-types>
<java-type name="Customer">
<xml-root-element/>
<xml-type prop-order="firstName lastName address phoneNumbers"/>
<java-attributes>
<xml-element java-attribute="firstName" name="first-name"/>
<xml-element java-attribute="lastName" name="last-name"/>
<xml-element java-attribute="phoneNumbers" name="phone-number"/>
</java-attributes>
</java-type>
<java-type name="PhoneNumber">
<java-attributes>
<xml-attribute java-attribute="type"/>
<xml-value java-attribute="number"/>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
For More Information
Upvotes: 1