i implement an simple REST-WebService with JAX-RS 2.0 and Glassfish 4. My problem is, if i send an Date or Calendar to the WS, the pojo lost the Dateinformation an the values are NULL.
In my WebService i set the Date tmp.setDate(1)
and in my JUnit-Test-Case i get the information [Thu Jan 01 02:00:00 CET 1970]
Any ideas why i lost the dateinformation by the request?
My Client (JUNIT)
@Test
public void testPOST() {
client = ClientBuilder.newClient();
this.root = this.client.target(SERVER + "/restExample/example");
OriginalSimpleDTO dto = new OriginalSimpleDTO();
dto.setDate(new Date(1));
final Entity<OriginalSimpleDTO> entity = Entity.entity(dto, mediaType);
Response response = this.root.request().post(entity);
System.out.println("POST Status " + response.getStatus());
OriginalSimpleDTO tmp = response.readEntity(OriginalSimpleDTO.class);
System.out.println("POST tmp-Date [" + tmp.getDate() + "]");
}
My WebSerice-Resource
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response testPost(OriginalSimpleDTO dto) {
System.out.println("dto date [" + dto.getDate() + "]");
OriginalSimpleDTO tmp = new OriginalSimpleDTO();
tmp.setDate(new Date(1));
return Response.ok(tmp).build();
}
My Pojo
@XmlRootElement
@JsonInclude (Include.NON_NULL)
public class OriginalSimpleDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Date datum;
//default Constructor
public OriginalSimpleDTO() {}
@JsonSerialize (using = DateSerializer.class)
public Date getDatum() {
return datum;
}
@JsonDeserialize (using = DateDeserializer.class)
public void setDatum(Date datum) {
this.datum = datum;
}
}