Note that there are some explanatory texts on larger screens.

plurals
  1. PODeserialize json with different object types
    primarykey
    data
    text
    <p>I get the following json from a httpresponse</p> <pre><code>{ "result": "success", "team_registration": { "current_status": "executed", "expiration_time": "2012-07-18T21:29:43Z", "id": 609, "team_id": 50, } } </code></pre> <p>How do I retreive the "result" as a string and the "team_registration" as a POJO (in Android) with Jackson?</p> <p>Currently I have this:</p> <pre><code>HttpResponse response = httpClient.execute(httpGet); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); String json = EntityUtils.toString(entity); Map&lt;String, Object&gt; map = mapper.readValue(json, new TypeReference&lt;Map&lt;String, Object&gt;&gt;() { }); result = (String) map.get("result"); resultRegistration = (Registration) map.get("team_registration"); </code></pre> <p>Registration class:</p> <pre><code>package be.radarwerk.app.model; import java.io.Serializable; import java.util.Date; import org.codehaus.jackson.annotate.JsonIgnore; public class Registration implements Serializable { // Todo implements parceable? private static final long serialVersionUID = 1L; private int id; private String currentStatus; private Date expirationTime; @JsonIgnore private Volunteer volunteer; @JsonIgnore private Team team; public Registration() { } public Registration(int id, String currentStatus, Volunteer volunteer, Team team) { super(); this.id = id; this.currentStatus = currentStatus; this.volunteer = volunteer; this.team = team; } public int getId() { return id; } public String getCurrentStatus() { return currentStatus; } public Volunteer getVolunteer() { return volunteer; } public Team getTeam() { return team; } public Date getExpirationTime() { return expirationTime; } } </code></pre> <p>"result" as String works fine but for the "registration_moment" I get this exception: java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to Registration</p> <p>I also tried casting it to a String in the same way as "result" and doing mapper.readValue on that string. No success.</p> <p>Any tips?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload