Deserializing non-string map keys with Jackson

前端 未结 3 1640
说谎
说谎 2020-12-01 14:35

I have a a map that looks like this:

public class VerbResult {
    @JsonProperty(\"similarVerbs\")
    private Map> similarVerbs         


        
3条回答
  •  没有蜡笔的小新
    2020-12-01 14:53

    Building on the answer given here that suggests to implement a Module with a deserializer. The JodaTime Module is an easy to understand full example of a module containing serializers and deserializers.

    Please note that the Module feature was introduced in Jackson version 1.7 so you might need to upgrade.

    So step by step:

    1. create a module containing a (de)serializer for your class based on the Joda example
    2. register that module with mapper.registerModule(module);

    and you'll be all set

提交回复
热议问题