我需要使用 org.codehaus.jackson
绝对按照我的方式反序列化 json 属性(字段)。我知道自定义 @JsonDeserializer
选项,但这仅在需要反序列化数组的给定值时才有用。我需要反序列化数组和数组本身的值。具体来说,我需要从 ORMLite 反序列化 ForreignCollection
,因此我应该能够以编程方式创建 ForeignCollectionField
并向其中添加值。
@JsonProperty
@ForeignCollectionField
private ForeignCollection<PerformerLocalized> localized;
有什么想法,如何管理?
最佳答案
@JsonDeserialize
可以同时用于容器和值,如下所示:
@JsonDeserialize(using=MyContainerDeserializer.class, // this would apply to Collection
contentUsing=ValueDeserializer.class) // and this to value type
请注意,通常 Collection
反序列化器不处理值,而只是委托(delegate)它(使事情很好地模块化)。但是您显然可以对反序列化器进行不同的选择;委托(delegate)或直接处理。如果你想委托(delegate),你可能想要实现 ContextualDeserializer
接口(interface),以便能够解析被委托(delegate)的反序列化器。
关于java - Jackson 中的自定义 JSON 数组反序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12396908/