Can't make Jackson and Lombok work together

后端 未结 14 1407
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 13:48

I am experimenting in combining Jackson and Lombok. Those are my classes:

package testelombok;

import com.fasterxml         


        
14条回答
  •  鱼传尺愫
    2020-11-27 14:09

    I've all my classes annotated like this:

    @JsonAutoDetect(fieldVisibility = Visibility.ANY)
    @JsonInclude(JsonInclude.Include.NON_DEFAULT)
    @Data
    @Accessors(fluent = true)
    @NoArgsConstructor
    @AllArgsConstructor
    

    It worked with all Lombok and Jackson versions for, at least, a couple of years.

    Example:

    @JsonAutoDetect(fieldVisibility = Visibility.ANY)
    @JsonInclude(JsonInclude.Include.NON_DEFAULT)
    @Data
    @Accessors(fluent = true)
    @NoArgsConstructor
    @AllArgsConstructor
    public class Person {
        String id;
        String first;
        String last;
    }
    

    And that's it. Lombok and Jackson play together like a charm.

提交回复
热议问题