Json 禁用某些序列化效率
我有一个实体,它有四个映射到同一实体的Json 禁用某些序列化效率,json,serialization,spring-boot,jackson,Json,Serialization,Spring Boot,Jackson,我有一个实体,它有四个映射到同一实体的@OneToOne: @Entity @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = TaxTable.class) public class TaxTable extends BaseEntity { @OneToOne( fetch = FetchType.LAZY) @JsonView(
@OneToOne
:
@Entity
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = TaxTable.class)
public class TaxTable extends BaseEntity {
@OneToOne( fetch = FetchType.LAZY)
@JsonView({Views.Summary.class, Views.Detailed.class})
private TaxRate taxRate1;
@OneToOne(fetch = FetchType.LAZY)
@JsonView({Views.Summary.class, Views.Detailed.class})
private TaxRate taxRate2;
@OneToOne(fetch = FetchType.LAZY)
@JsonView({Views.Summary.class, Views.Detailed.class})
private TaxRate taxRate3;
@OneToOne(fetch = FetchType.LAZY)
@JsonView({Views.Summary.class, Views.Detailed.class})
private TaxRate taxRate4;
}
当我从控制器中检索TaxTable时,我得到以下信息:
{
"id": 1,
"taxRate1": {
"id": 1,
// more properties here
},
"taxRate2": 1,
"taxRate3": 1,
"taxRate4": 1
}
这是因为它们都引用同一个对象。但是有没有办法告诉杰克逊不要这么有效率?我看了一遍,但找不到任何具体的信息。“告诉杰克逊不要这么有效率”。你能详细解释一下这句话吗?我希望taxRate1-4都有完整的TaxRate对象。正如我在问题中所说,因为它们都是同一个物体,杰克逊只给了我一次完整的物体。这通常是有帮助的,但在我当前的用例中,我不希望发生这种情况。