如何创建没有为特定字段分配值的Json有效负载?

时间:2018-02-12 00:45:06

标签: json model jackson fasterxml

如果我想使用fasterxml.jackson创建如下的Json有效负载,我该怎么办?

{
    "email":
}

这就是我的模型类的样子:

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import java.io.Serializable;

@JsonInclude(JsonInclude.Include.ALWAYS)
@JsonPropertyOrder({ "email" })
public class ApiRequest implements Serializable {

    private static final long serialVersionUID = 1L;

    @JsonProperty("email")
    private String email;

    public ApiRequest() {
    }

    /**
     * @param email
     */
    public ApiRequest(String email) {
        this.email = email.equalsIgnoreCase("null") ? null : email;
    }

    @JsonProperty("email")
    public String getEmail() {
        return email;
    }

    @JsonProperty("email")
    public void setEmail(String email) {
        this.email = email.equalsIgnoreCase("null") ? null : email;
    }
}

谢谢!

0 个答案:

没有答案