How to specify jackson to only use fields - preferably globally

前端 未结 8 529
旧巷少年郎
旧巷少年郎 2020-11-22 17:03

Default jackon behaviour seems to use both properties (getters and setters) and fields to serialize and deserialize to json.

I would like to use the fields as the ca

8条回答
  •  感情败类
    2020-11-22 17:36

    for jackson 1.9.10 I use

    ObjectMapper mapper = new ObjectMapper();
    
    mapper.setVisibility(JsonMethod.ALL, Visibility.NONE);
    mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
    

    to turn of auto dedection.

提交回复
热议问题