Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use a custom deserializer for your use case. Here is what it will look like:</p> <pre class="lang-java prettyprint-override"><code>import java.io.IOException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; public class StudyDeserializer extends JsonDeserializer&lt;Study&gt; { @Override public Study deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { JsonNode studyNode = parser.readValueAsTree(); Study study = new Study(); study.setStudyId(studyNode.get("studyId").asInt()); Patient patient = new Patient(); JsonNode patientNode = studyNode.get("patient"); patient.setPatientId(studyNode.get("patientId").asInt()); patient.setName(patientNode.get("name").asText()); patient.setLastName(patientNode.get("lastName").asText()); study.setPatient(patient); return study; } } </code></pre> <p>Specify the above class as your deserializer in the <code>Study</code> class:</p> <pre class="lang-java prettyprint-override"><code>import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonDeserialize(using = StudyDeserializer.class) public class Study { Integer studyId; Patient patient; // Getters and setters } </code></pre> <p>Now, the JSON input you have specified should get deserialized as expected.</p>
 

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