Want to hide some fields of an object that are being mapped to JSON by Jackson

后端 未结 7 1907
北海茫月
北海茫月 2020-11-30 03:45

I have a User class that I want to map to JSON using Jackson.

public class User {
    private String name;
    private int age;
    prviate int securityCode;         


        
7条回答
  •  眼角桃花
    2020-11-30 04:23

    if you are using GSON you have to mark the field/member declarations as @Expose and use the GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()

    Don't forget to mark your sub classes with @Expose otherwise the fields won't show.

提交回复
热议问题