How to ignore a certain attribute when java returns the front-end entity class json data

scenes to be used:

There is a Json string in development that needs to be processed into a JSON object for return, so the original field does not need to be returned, only the processed one.

Processing logic:

It can be achieved using @JsonIgnore annotation

@Data 
public class UserVO { 
    /** 
     * User id 
     */ 
    private Integer id; 
    /** 
     * Username 
     */ 
    private String username; 
    /** 
     * Password 
     */ 
    private String password; 
    /** 
     * Name 
     */ 
    private String truename; 
    /** 
     * Role name 
     */ 
    private String rolename; 
    /** 
     * Email 
     */ 
    private String emailaddress; 
    /** 
     * Queue 
     */ 
    @JsonIgnore 
    private String project; 
    private JsonNode projectJson;
    /**
     * 班组
     */
    private String groupname;
    /**
     * 是否启用
     */
    private boolean enabled;

    public void setProject(String project) throws IOException {
        this.project = project;
        if (project!=null){
            this.projectJson = JsonUtil.stringToJsonNode(project);
        }
    }
}

Note: String to JsonNode object method 

/**
 * json字符串抓换成JsonNode对象
 * @param jsonString
 * @return
 */
public static JsonNode stringToJsonNode(String jsonString) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode userJsonNode = null;
    userJsonNode = mapper.readTree(jsonString);
    return userJsonNode;
}

Guess you like

Origin blog.csdn.net/wangpei930228/article/details/109000389