I know this kind of question was raised in the past but not exactly the same issue so i found the right to ask this question.
I'm using JERSEY together with JACKSON for REST web service (JAVA 1.8_011 + Tomcat v7.0 + windows 7 + JERSEY-common 2.23.2 + JACKSON 2.8.2)
One of my POJO field has the following setter:
public void setEndDate(LocalDateTime endDate) {
if (this.startDate != null && this.startDate.isAfter(endDate))
{
throw new IllegalArgumentException("Start date must to be before End date");
}
this.endDate = endDate;
}
my web service is the following:
@PUT
@Path("/updateCoupon")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String updateCoupon(Coupon coupon) {
try
{
//Coupon tmpCoupon = new Coupon(coupon);
System.out.println("*" + coupon.getEndDate().toString() + "*");
getFacade().updateCoupon(coupon);
return "ok";
}
catch (FacadeException | IllegalArgumentException e)
{
return e.getMessage();
}
}
JSON:
{
"startDate":"2016-11-04T00:00",
"endDate":"2016-11-09T00:00",
"amount":7,
"id":143,
"image":"390_290_5cc10a4d-9a3f-4cfc-8.jpg",
"message":"gfd",
"price":3.34,
"title":"n37",
"type":"HEALTH"
}
After debugging and tests the problem is that the JSON does not use my setter to transform from JSON to the POJO (it happens in more setters so the setter it self is not the issue)
Thanks