JAXB Tag Wrapper

Suppose I have a Java class as follows

public class Foo { public ... getKitchen(){} public ... getRoom(){} public ... getInnerPart(){} public ... getUpperPart(){} public ... getBasement(){} ... ... } 

and I want the XML output to look like this

 <foo> <house> <kitchen>value<kitchen> <basement>value<basement> <room>value<room> <house> <innerPart>value<innerPart> <upperPart>value<upperPart> <foo> 

What would be the JAXB annotations in my class? Thanks.

+4
source share
1 answer

Note. I am EclipseLink JAXB (MOXy) and a member of the JAXB 2 group (JSR-222) .

You can use the MOXy @XmlPath to achieve this correspondence:

 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(){} ... ... } 

Additional Information

+3
source

Source: https://habr.com/ru/post/1384218/


All Articles