I am trying to store the response I got in JSON in my database in spring boot. But when it shows JSON Parse Error
This is my JSON response
[
{
id: 1,
name: "Bilbo Baggins",
location: "india",
email: "jba2hba.com",
dateOfBirth: "2020-12-21T13:13:38.000+00:00"
},
{
id: 2,
name: "Frodo Baggins",
location: "bhutan",
email: "jhb@hbh.com",
dateOfBirth: "2020-12-21T13:13:38.000+00:00"
}
]
My Employee model
@Entity
public class Employee {
private @Id @GeneratedValue( strategy = GenerationType.AUTO ) Long id;
private String name;
private String location;
private String email;
private Date dateOfBirth;
public Employee() {
}
public Employee(String name, String location, String email, Date date) {
this.name = name;
this.location = location;
this.email = email;
this.dateOfBirth = date;
}
//getters and setters
My getEmployees() method
public void getEmployees() {
RestTemplate restTemplate = new RestTemplate();
Employee result = restTemplate.getForObject(Constants.URI, Employee.class);
System.out.println(result);
}
This is the error I am getting
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.nagarro.hrLogin.entity.Employee` out of START_ARRAY token
at [Source: (PushbackInputStream); line: 1, column: 1]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1468) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1242) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1190) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeFromArray(BeanDeserializer.java:604) ~[jackson-databind-2.11.3.jar:2.11.3]
//
I am not able to figure what might be causing the error if anybody could suggest me somethiing it would be really helpful