2012-09-12 158 views
2

我需要使用org.codehaus.jackson絕對地反序列化json屬性(字段)。我知道自定義@JsonDeserializer選項,但這只是有用的,如果你需要反序列化給定的數組值。我需要反序列化數組和數組本身的值。具體來說,我需要從ORMLite反序列化ForreignCollection,所以我應該能夠以編程方式創建ForeignCollectionField並向其中添加值。Jackson中的自定義JSON數組反序列化

@JsonProperty 
@ForeignCollectionField 
private ForeignCollection<PerformerLocalized> localized; 

有沒有什麼想法,如何管理它?

回答

3

@JsonDeserialize既可以用容器和價值觀,就像這樣:

@JsonDeserialize(using=MyContainerDeserializer.class, // this would apply to Collection 
    contentUsing=ValueDeserializer.class) // and this to value type 

注意,通常Collection解串器不處理值,而只是委託它(把事情很好地模塊化)。但你顯然可以選擇與你的反序列化器不同的方式;代表或直接處理。如果你想委託,你可能想要實現ContextualDeserializer接口,以便能夠解析delegatee解串器。