开发者

Can XmlJavaTypeAdapter marshal object to another object?

开发者 https://www.devze.com 2022-12-15 02:22 出处:网络
Can XmlJavaTypeAdapter marshal from ClassA object to ClassB object? So that when : public void createCla开发者_开发技巧ssB (ClassB b) { }

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:

  1. Annotate both classes with the same annotations
  2. When marshalling, put only your ClassA in the JAXB Context
  3. When unmarshalling, put only your ClassB in the JAXB Context
0

精彩评论

暂无评论...
验证码 换一张
取 消