lundi 4 juillet 2016

Google JsonFactory (JacksonFactory) fromString not working - all fields are null

I have an object:

@JsonIgnoreProperties(ignoreUnknown = true) public class OauthPrincipal { @JsonProperty String id;

@JsonProperty
String name;

@JsonProperty
String email;

public OauthPrincipal() {
}

public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}
... other [get|set]ters

Which works when I do:

    final String jsonIdentity = request.execute().parseAsString();
    debug(jsonIdentity);
    ObjectMapper om = new ObjectMapper();
    OauthPrincipal o;
    o = om.readValue(jsonIdentity, OauthPrincipal.class);
    return o;

But when I use JsonFactory (Which is a new JacksonFactory() all fields are null for the same JSON

jf.fromString(json, OauthPrincipal.class

JSON from log is :

07:31:44,040 ERROR [stderr] (default task-6)  {
07:31:44,040 ERROR [stderr] (default task-6)  "id": "11",
07:31:44,040 ERROR [stderr] (default task-6)  "email": "example@gmail.com",
07:31:44,040 ERROR [stderr] (default task-6)  "verified_email": true,
07:31:44,040 ERROR [stderr] (default task-6)  "name": "mike",
07:31:44,040 ERROR [stderr] (default task-6)  "given_name": "mike",
07:31:44,040 ERROR [stderr] (default task-6)  "family_name": "b",
07:31:44,040 ERROR [stderr] (default task-6)  "link": "https://plus.google.com/xyz",
07:31:44,040 ERROR [stderr] (default task-6)  "picture": "https://lh3.googleusercontent.com/snipped/photo.jpg",
07:31:44,040 ERROR [stderr] (default task-6)  "locale": "en"
07:31:44,040 ERROR [stderr] (default task-6) }

Aucun commentaire:

Enregistrer un commentaire