Trying to read the below json and map to properties in the class. Sample code below.
String jsonStr = "{\n" +
"\"requestIds\": [20123, 20124],\n" +
"\"resource\": {\n" +
"\"resourceId\": \"N\",\n" +
"\"debitTypeId\": \"11\",\n" +
"\"part\": \"NAN\",\n" +
"\"showAlertedTddOnly\": false,\n" +
"\"acknowledgement\": \"UNACKNOWLEDGED\",\n" +
"\"managerEngineer\": null,\n" +
"\"route\": [{\n" +
"\"rowNum\": null,\n" +
"\"columnNum\": \"12\"\n" +
"},\n" +
"{\n" +
"\"rowNum\": \"#\",\n" +
"\"columnNum\": \"13\",\n" +
"\"rowIdent\": \"SIGN\"\n" +
"}\n" +
"]\n" +
"}\n" +
"}";
ObjectMapper om = new ObjectMapper();
ResourceCallRequest models = om.readValue(jsonStr, ResourceCallRequest.class);
Below is the model class to which i want to map the above json.
@Getter
@Setter
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ResourceCallRequest {
List<Integer> requestIds;
String resource;
Exception :
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token
at [Source: (String)"{
}
In the ResourceCallRequest class, after reading the jsonString, i want to map requestIds from json to List<Integer> requestIds
and resource from jsonStr to String resource
.
Expected output to map to properties are as below.
List<Integer> requestIds = [20123, 20124]
String resource = "{\n" +
"\"resourceId\": \"N\",\n" +
"\"debitTypeId\": \"11\",\n" +
"\"part\": \"NAN\",\n" +
"\"showAlertedTddOnly\": false,\n" +
"\"acknowledgement\": \"UNACKNOWLEDGED\",\n" +
"\"managerEngineer\": null,\n" +
"\"route\": [{\n" +
"\"rowNum\": null,\n" +
"\"columnNum\": \"12\"\n" +
"},\n" +
"{\n" +
"\"rowNum\": \"#\",\n" +
"\"columnNum\": \"13\",\n" +
"\"rowIdent\": \"SIGN\"\n" +
"}\n" +
"]\n" +
"}";