如何将日期值发送到 Web 服务请求中的日历对象。
@Produces("application/json")
@Path("Service")
public class ServiceImpl {
@Context
HttpServletRequest httpServletRequest;
@Context
HttpServletResponse httpServletResponse;
@POST
@Path("getDetails")
@Consumes("application/json")
@Produces("application/json")
public String getDetails (ServiceRequest request)
{
if(null!=request)
return "Successfully Parsed given Date";
}
}
public class ServiceRequest {
private XMLGregorianCalendar requestDate;
void setDate(XMLGregorianCalendar date){
this.requestDate = date;
}
XMLGregorianCalendar getDate()
{
return requestDate;
}
}
请求网址: http://localhost:7001/WebProject/Service/getDetails
请求参数:
{
"requestDate" : "2015-04-20T05:30:00.000Z"
}
它没有将值解析为日期。我如何传递日历对象的值。
我正在使用 genson jar 序列化请求。错误信息就像
Caused by: com.owlike.genson.JsonBindingException: Could not parse date 2015-04-20T05:11:00.000Z
at com.owlike.genson.convert.DefaultConverters$DateConverter.deserialize(DefaultConverters.java:1003)
at com.owlike.genson.convert.DefaultConverters$CalendarConverter.deserialize(DefaultConverters.java:1226)
at com.owlike.genson.convert.DefaultConverters$CalendarConverter.deserialize(DefaultConverters.java:1209)
at com.owlike.genson.convert.BeanViewConverter.deserialize(BeanViewConverter.java:102)
at com.owlike.genson.convert.NullConverter$NullConverterWrapper.deserialize(NullConverter.java:56)
at com.owlike.genson.reflect.PropertyMutator.deserialize(PropertyMutator.java:30)
... 48 more
Caused by: java.text.ParseException: Unparseable date: "2015-04-20T05:11:00.000Z"
at java.text.DateFormat.parse(DateFormat.java:337)
at com.owlike.genson.convert.DefaultConverters$DateConverter.read(DefaultConverters.java:1009)
at com.owlike.genson.convert.DefaultConverters$DateConverter.deserialize(DefaultConverters.java:1001)
... 53 more