2016-03-31 2 views
1

Я получил User класс, который выглядит примерно так:Android retrofit2 отправкой JSON через Джексон

public class User implements Serializable { 

    @JsonProperty("image") 
    private UserImage image; 

    @JsonProperty("email") 
    private String email; 

    @JsonProperty("mobilePhone") 
    private String mobilePhone; 

    @JsonProperty("firstname") 
    private String firstName; 

    @JsonProperty("lastname") 
    private String lastName; 

    @JsonProperty("codeCreatedAt") 
    private String codeCreatedAt; 

    @JsonProperty("accountSettings") 
    private AccountSettings accountSettings; 

    @JsonProperty("status") 
    private String status; 

    @JsonProperty("created") 
    private String created; 

    @JsonProperty("id") 
    private String id; 

    public User(String lastName, String firstName, String mobilePhone) { 
     this.lastName = lastName; 
     this.firstName = firstName; 
     this.mobilePhone = mobilePhone; 
    } 

    public User() { 
    } 

    public User(UserImage image, String email, String mobilePhone, String firstName, String lastName, String codeCreatedAt, AccountSettings accountSettings, String status, String created, String id) { 
     this.image = image; 
     this.email = email; 
     this.mobilePhone = mobilePhone; 
     this.firstName = firstName; 
     this.lastName = lastName; 
     this.codeCreatedAt = codeCreatedAt; 
     this.accountSettings = accountSettings; 
     this.status = status; 
     this.created = created; 
     this.id = id; 
    } 
} 

Я пытаюсь отправить JSon как: {"mobilePhone":"123456789","lastname":"test","firstname":"test"}

создать новый пользователь, с помощью конструктора с 3 параметрами, но делает JSON основанным на конструкторе со всеми параметрами. Что мне нужно изменить, чтобы получить желаемый JSON?

ответ

2

добавить @JsonInclude(JsonInclude.Include.NON_NULL) к классу

@JsonInclude(JsonInclude.Include.NON_NULL) 
public class User implements Serializable {...} 
Смежные вопросы