如何使用 JSON-B 序列化瞬态 属性?
How to use JSON-B to serialize a transient property?
给定一个
public class Foo {
private String x;
transient private String y;
public String getX() {
return x;
}
public void setX(String x) {
this.x = x;
}
public String getY() {
return y;
}
public void setY(String y) {
this.y = y;
}
}
如何指示 JSON-B 序列化 属性 y
?
这是在 JPA 上下文 (@Entity
) 中使用类型 Foo
的情况,其中 transient
表示不应保留 属性。
不使用 transient
关键字,而是使用 @javax.persistence.Transient
注释对该字段进行注释。
即
@Transient
private String y;
实际上,这使得 属性 可用于 JSON-B 进行序列化。
给定一个
public class Foo {
private String x;
transient private String y;
public String getX() {
return x;
}
public void setX(String x) {
this.x = x;
}
public String getY() {
return y;
}
public void setY(String y) {
this.y = y;
}
}
如何指示 JSON-B 序列化 属性 y
?
这是在 JPA 上下文 (@Entity
) 中使用类型 Foo
的情况,其中 transient
表示不应保留 属性。
不使用 transient
关键字,而是使用 @javax.persistence.Transient
注释对该字段进行注释。
即
@Transient
private String y;
实际上,这使得 属性 可用于 JSON-B 进行序列化。