Can XmlJavaTypeAdapter marshal from ClassA object to ClassB object? So that when :
public void createCla开发者_开发技巧ssB (ClassB b) { }
I can pass in ClassA object. Does it possible?
Yes it can, but not quite like this. I mean you can not pass a ClassA
object, where ClassB
is required, unless ClassA
is a sub-class of ClassB
. Read through this example, its showing how you can marshal a Currency
object as a String
into your XML. So, quiet similar to the example, you should be able to marshal ClassA object to ClassB or something.
A little different solution, which is odd, and which you probably aren't looking for, but anyway:
- Annotate both classes with the same annotations
- When marshalling, put only your
ClassA
in the JAXB Context - When unmarshalling, put only your
ClassB
in the JAXB Context
精彩评论