1
請注意,通過序列化,我的意思是序列化爲JSON(JsonNode或其字符串表示形式)。Jackson:只序列化給定類的給定實例變量
這是傑克遜2.2.3。我的階級是這樣的:
public final class Foo
{
// the one and only instance variable
private final List<Bar> l;
// Allows deserialization with no problem at all
@JsonCreator
public Foo(final List<Bar> l)
{
this.l = ImmutableList.copyOf(l);
}
}
我已經知道如何序列化所有Bar
實例(測試)。現在我需要能夠序列化一個Foo
實例。
我已經能夠在此刻做的唯一一件事情就是「裝飾」 l
與@JsonSerialize
註解,但是這給:
{ "l": [ { "serializedForm": "of bar1"}, { "serializedForm": "of bar2"} ] }
而且我想:
[ { "serializedForm": "of bar1"}, { "serializedForm": "of bar2"} ]
怎麼辦我做到了嗎?注意:我可以使用jackson-annotations
另請注意,我可以將第二個表單完美反序列化爲有效的實用Foo
實例。
對不起,但我不同意。我可以將Bar的JSON數組完全反序列化爲Foo。見[這裏](https://github.com/fge/json-patch/blob/master/src/main/java/com/github/fge/jsonpatch/JsonPatch.java#L121)。 – fge
@fge在你的字段的getter上有'@ JsonValue'的解決方法。 –
好的,但事情是,這個領域沒有getter:/ – fge