REST API に複雑なクラスがあります。
class Complicated {
String foo
Integer bar
Instant baz
...
// lots more
}
次のコレクションを含む別のクラスもありますComplicated
。
class HasComplications {
String description
List<Complicated> complications
}
(Spring MVC を使用して)シリアライズするときはHasComplications
、それぞれのスニペットのみが必要ですComplicated
。
{
description: "hello world",
complications: [ {
foo: "foo1",
bar: 42
] }
}
を直接シリアル化するComplicated
場合、 を使用@JsonView
して、シリアル化するプロパティのセットを Jackson に伝えることができます。
class Complicated {
@JsonView(Views.Snippet) String foo
@JsonView(Views.Snippet) Integer bar
Instant baz
...
// lots more
}
ただし、プロパティでComplicated
推移的にシリアル化するcomplications
と、ジャクソンはすべてのプロパティをシリアル化します。「このプロパティをシリアル化するときにこのビューを使用する」と宣言的に伝える方法はありますか?
class HasComplications {
String description
@UseJsonView(Views.Snippet)
List<Complicated> complications
}