Jackson Custom Deserializer nicht genanntJava

Java-Forum
Anonymous
 Jackson Custom Deserializer nicht genannt

Post by Anonymous »

Ich habe den folgenden Endpunkt im Nachrüst: < /p>

Code: Select all

@GET("user/detail")
Observable getUserDetail();
< /code>
Dieser Endpunkt gibt das folgende Ergebnis zurück: < /p>
{
"code":1012,
"status":"sucess",
"message":"Datos Del Usuario",
"time":"28-10-2015 10:42:04",
"data":{
"id_hash":977417640,
"user_name":"test",
"user_surname":"test1",
"birthdate":"1994-01-12",
"height":190,
"weight":80,
"sex":2,
"photo_path":" https:\/\/graph.facebook.com
\/422\/picture?width=100&height=100"
}
}
< /code>
Hier ist die Definition der Klasse: < /p>
public class JacksonResponse {

private Integer code;
private String status;
private String message;
private String time;
@JsonInclude(JsonInclude.Include.NON_NULL)
private T data;

public JacksonResponse(){}

@JsonCreator
public JacksonResponse(
@JsonProperty("code") Integer code,
@JsonProperty("status") String status,
@JsonProperty("message") String message,
@JsonProperty("time") String time,
@JsonProperty("data") T data) {
this.code = code;
this.status = status;
this.message = message;
this.time = time;
this.data = data;
}

public Integer getCode() {
return code;
}

public void setCode(Integer code) {
this.code = code;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public String getTime() {
return time;
}

public void setTime(String time) {
this.time = time;
}

public T getData() {
return data;
}

public void setData(T data) {
this.data = data;
}

}
< /code>
Ich möchte, dass der Inhalt "Daten" der Benutzerklasse zugeordnet ist, deren Extrakt hier anzeigen: < /p>
@JsonIgnoreProperties(ignoreUnknown = true)
@ModelContainer
@Table(database = AppDatabase.class)
public class User extends BaseModel {

@PrimaryKey(autoincrement = true)
private Long id;
@Column
private Long idFacebook;
@Column
@JsonProperty("user_name")
private String name;
@Column
@JsonProperty("user_surname")
private String surname;
@Column
private Date birthday;
@Column
@JsonProperty("height")
private Double height;
@Column
@JsonProperty("weight")
private Double weight;
@Column
private String tokenFacebook;
@Column
@JsonProperty("sex")
private Integer sex;
@Column
private String email;
@Column
private String token;
@Column
private Date lastActivity;
@Column
@JsonProperty("id_hash")
private Long idHash;
@Column
@JsonProperty("photo_path")
private String photoPath;
< /code>
Zu Geburtsdatum habe ich einen benutzerdefinierten Deserializer definiert, dessen Code hier angezeigt wird: < /p>
public class BirthdayDeserializer extends JsonDeserializer  {
@Override
public Date deserialize(JsonParser jsonparser, DeserializationContext deserializationcontext) throws IOException {

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = jsonparser.getText();
try {
return format.parse(date);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}

}
< /code>
Ich benutze dies wie folgt (bei Benutzerklasse): < /p>
@JsonProperty("birthday")
@JsonDeserialize(using = BirthdayDeserializer.class)
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
, aber dies wird nie genannt.
Irgendeine Idee, was ist los?>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post