Jackson serialize only interface methods

前端 未结 2 2084
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-04 01:36

I have one object A with some methods ma, mb, mc and this object implements an interface B with only ma and mb

2条回答
  •  悲&欢浪女
    2021-01-04 02:20

    You have two options:

    1) put @JsonSerialize annotation on your interface (see @broc.seib answer)

    2) or use specific writer for the serialization (as of Jackson 2.9.6):

    ObjectMapper mapper = new ObjectMapper();
    String str = mapper.writerFor(Interf.class).writeValueAsString(interf);
    

提交回复
热议问题