1
プロジェクトは、2つのエンティティがあります:Gsonやジャクソンを使用してJSONへJSONにエンティティを休止状態に変換:全体ではなく、オブジェクトのoblectId
@Entity
public class Customer {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "city_id", nullable = true)
private City city;
...
}
と
@Entity
public class City {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@Column(name = "name", nullable = false)
private String name;
...
}
Cutomerエンティティは
{
"id":1,
"city":{"id":1, "name":"New York"}
}
として変換し、
私はそれが変換されたいので
{
"id":1,
"city_id":1
}
私はgsonやjacksonからどうすればいいですか?
これを実現するには、カスタムシリアライザを使用する必要があります。 @Satmurat –
このリンクで自分の回答を確認してください> [シリアライザのカスタマイズ方法](https://stackoverflow.com/questions/35592831/should-serialization-logic-be-in-the-entity-or-other-class/35593831#35593831) –
@VikrantKashyap、各エンティティのシリアライザの作成がうまくいかない。 – Satmurat