gpt4 book ai didi

java - 使用 JAXB 以不同方式编码模型

转载 作者:行者123 更新时间:2023-11-29 08:54:04 25 4
gpt4 key购买 nike

当然,这个问题之前在任何地方都被问过,但没有找到合适的解决方案:

是否有可能使用 JAXB 将模型编码为不同的 XML 或以不同的方式编码。我仍然使用 Jackson 将此模型序列化为 JSON,我可以在其中使用 @JsonView 或 JsonMixins将其序列化为不同的 json 布局。

有这个模型:

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;
}

应该编码为:

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

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

我找到了 thisthis在 stackoverflow 上发帖,但建议使用 EclipseLink JAXB。但不幸的是,作为持久性提供者的 Hibernate 仍在使用中。 EclipseLink 和 Hibernate(两者都是 O/R 映射器)不会真正一起工作 - 不是吗?

是否可以使用 JAXB 将模型编码到不同的 xml?

最佳答案

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 提供 JPA (O/R) 和 MOXy (O/X (JAXB) & O/J)。您可以毫无问题地将 EclipseLink O/X 与 Hibernate O/R 一起使用。

EclipseLink MOXy您可以使用对象图功能将模型的子集输出为 XML 或 JSON。

关于java - 使用 JAXB 以不同方式编码模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21261566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com