I encountered an issue while attempting to send a value to my controller.
Failed to read HTTP message:
org.springframework.http.converter.HttpMessageNotReadableException: Could
not parse JSON document: Unable to deserialize java.lang.String from START_OBJECT token
at [Source: java.io.PushbackInputStream@355134ca; line: 1, column: 655]
(through reference chain: com.csps.gabriel.entities.Policy["goodsList"]-
>java.util.ArrayList[0]->com.csps.gabriel.dtos.GoodsDto["type"]); nested
exception is com.fasterxml.jackson.databind.JsonMappingException: Unable
to deserialize java.lang.String from START_OBJECT token
at [Source: java.io.PushbackInputStream@355134ca; line: 1, column: 655]
(through reference chain: com.csps.gabriel.entities.Policy["goodsList"]-
>java.util.ArrayList[0]->com.csps.gabriel.dtos.GoodsDto["type"])
This is the JSON I posted:
{
"client": {
"clientId": 1000002,
"firstName": "Jose Anibal",
"lastName": "Rodriguez Lopez",
"idCard": "07200140809",
...
}]
}
This piece of code represents the entity that maps the request body:
@Entity
@Table(name = "policy")
public class Policy {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "policy_id")
...
}
}
This is the defined controller:
@RestController
public class PolicyController {
@Autowired
PolicyRepository policyRepository;
@RequestMapping(value = "/save-policy", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
...
}
}
This snippet presents the GoodsList class:
package com.csps.gabriel.dtos;
import java.io.Serializable;
/**
Created by Jose A Rodriguez on 5/20/2017.
*/
public class GoodsDto implements Serializable{
private static final long serialVersionUID = 1L;
...
}
}
If anyone has any insights on why this error is occurring, please share. Thank you in advance!