Jackson + Builder Pattern?

前端 未结 6 1811
春和景丽
春和景丽 2020-11-28 20:23

I\'d like Jackson to deserialize a class with the following constructor:

public Clinic(String name, Address address)

Deserializing the firs

6条回答
  •  盖世英雄少女心
    2020-11-28 21:08

    The answer from @Rupert Madden-Abbott works. However, if you have a non-default constructor, e.g.,

    Builder(String city, String country) {...}
    

    Then you should annotate the parameters as below:

    @JsonCreator
    Builder(@JsonProperty("city")    String city, 
            @JsonProperty("country") String country) {...}
    

提交回复
热议问题