简体   繁体   中英

Marshal model in different ways using JAXB

Sure, this question was asked before anywhere but didn't find a appropriate solution for it:

Is there a possibility to marshal a model with JAXB to different XMLs or in different ways. I still serialize this model to JSON with Jackson where I can use @JsonView or JsonMixins to serialize it to different json layouts.

Having this model:

public class Customer {
    public int getId() { return id; }
    public void setId(int id) { this.id = id; }
    private int id;

    public String getLastName() { return lastName; }
    public void setLastName(String lastName) { this.lastName = lastName; }
    private String lastName;

    public String getFirstName() { return firstName; }
    public void setFirstName(String firstName) { this.firstName = firstName; }
    private String firstName;
}

should be marshalled as:

<customer>
    <lastName>name</lastName>
<customer>

or

<customer>
    <id>name</id>
    <lastName>name</lastName>
    <firstName>firstname</firstName>
<customer>

I found this and this posting on stackoverflow but the suggestion is to use EclipseLink JAXB. But unfortunately Hibernate as a persistence provider is still in use. EclipseLink and Hibernate (both are O/R mapper) won't really work together - isn't it?

Is there any possibilty to marshal a model to different xml using JAXB?

I found this and this posting on stackoverflow but the suggestion is to use EclipseLink JAXB. But unfortunately Hibernate as a persistence provider is still in use. EclipseLink and Hibernate (both are O/R mapper) won't really work together - isn't it?

EclipseLink provides JPA (O/R) and MOXy (O/X (JAXB) & O/J). You can use the EclipseLink O/X with Hibernate O/R without issue.

With EclipseLink MOXy you can use the Object Graph feature to output subsets of your model to XML or JSON.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM