假设我有一个Java类如下
public class Foo {
public ... getKitchen(){}
public ... getRoom(){}
public ... getInnerPart(){}
public ... getUpperPart(){}
public ... getBasement(){}
...
...
}
我希望像这样的XML输出
<foo>
<house>
<kitchen>value<kitchen>
<basement>value<basement>
<room>value<room>
<house>
<innerPart>value<innerPart>
<upperPart>value<upperPart>
<foo>
我班上的JAXB注释会是什么样子? 感谢。
答案 0 :(得分:3)
注意:我是 EclipseLink JAXB (MOXy) 负责人,也是JAXB 2 (JSR-222)专家组的成员。
您可以使用MOXy的@XmlPath
扩展名来实现此映射:
import javax.xml.bind.annotation.*;
import org.eclipse.persistence.oxm.annotations.XmlPath;
@XmlRootElement
@XmlType(propOrder={"kitchen", "basement", "room", "innerPart", "upperPart"})
public class Foo {
@XmlPath("house/kitchen/text()")
public ... getKitchen(){}
@XmlPath("house/room/text()")
public ... getRoom(){}
public ... getInnerPart(){}
public ... getUpperPart(){}
@XmlPath("house/basement/text()")
public ... getBasement(){}
...
...
}
了解更多信息