Jackson serialize only interface methods

前端 未结 2 2100
佛祖请我去吃肉
佛祖请我去吃肉 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:21

    Just annotate your interface such that Jackson constructs data fields according to the interface's class and not the underlying object's class.

    @JsonSerialize(as=Interf.class)
    public interface Interf {
      public boolean isNo();
      public int getCountI();
      public long getLonGuis();
    }
    

提交回复
热议问题