I Cannot deserialize instance of `java.lang.String` out of START_OBJECT token

Viewed 3953

i am trying map a json file to json object but i am getting an error as cannot deserialize string out of start_object token.

This is my json file

{
    "serial_key": 2,
    "serial_identity" : "20200580011000",
    "serial_type" : "I",
    "serial_source" : "NASA"
    "serial_detail" : {
            "serialID": "20200580011000",
            "patient": {
                "name": {
                    "fullName": "John Mathew",
                    "lastName": "John",
                    "firstName": "Mathew"
                },
                "gender": "Female",
                "century": "0",
                "dateOfBirth": 252460800000,
                "admissionStatus": "active"
            }
        }
    }

Below is my mapping class

@Data
@NoArgsConstructor
@AllArgsConstructor
public class SerialDto { 

    @JsonProperty("serial_key")
    private Long serialKey;

    @JsonProperty("serial_identity")
    private String serialIdentity;

    @JsonProperty("serial_type")
    private String serialType;

    @JsonProperty("serial_source")
    private String serialSource;

    @JsonProperty("serial_detail")
    private String serialDetail;

}

Below is the code to map it

String json;
        ObjectMapper mapper = new ObjectMapper();
        try {
            json = FileUtils.readFileToString(new File("src/main/resources/test.json"), StandardCharsets.UTF_8);
            SerialDto dto = mapper.readValue(json, SerialDto.class);    
            System.out.println(dto.getSerialIdentity());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

The exception which i am getting is

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token
(through reference chain: com.app.entity.SerialDto["serial_detail"])

can anyone help to bind the serial_detail to the string of serialDetail where is there the json format need to be modified in order to get the serial_detail as json string?

0 Answers
Related