相关疑难解决方法(0)

杰克逊序列化:忽略空值(或null)

我目前正在使用jackson 2.1.4,当我将对象转换为JSON字符串时,我在忽略字段时遇到了一些麻烦.

这是我的类,它充当要转换的对象:

public class JsonOperation {

public static class Request {
    @JsonInclude(Include.NON_EMPTY)
    String requestType;
    Data data = new Data();

    public static class Data {
        @JsonInclude(Include.NON_EMPTY)
        String username;
        String email;
        String password;
        String birthday;
        String coinsPackage;
        String coins;
        String transactionId;
        boolean isLoggedIn;
    }
}

public static class Response {
    @JsonInclude(Include.NON_EMPTY)
    String requestType = null;
    Data data = new Data();

    public static class Data {
        @JsonInclude(Include.NON_EMPTY)
        enum ErrorCode { ERROR_INVALID_LOGIN, ERROR_USERNAME_ALREADY_TAKEN, ERROR_EMAIL_ALREADY_TAKEN };
        enum Status { ok, error };

        Status status; …
Run Code Online (Sandbox Code Playgroud)

java json jackson

131
推荐指数
6
解决办法
27万
查看次数

标签 统计

jackson ×1

java ×1

json ×1