I have a problem with DATE
format and sending it (as an attribute from an entity named thesisDTO
) via REST-Webservice (JSON).
I want to call a webservice method (POST-request) which excepts a DATE
in the following format:
{ ...
"proposalDate":"Feb 17, 2022 7:50:09 AM" }
If I create a DATE variable with the following code, the method "toString()
"gives me the right format:
Date currentDate = new Date();
IsyMNDLogger.getLogger().info("Date To String: "+currentDate.toString());
But if I add currentDate
to my object thesisDTO
with:
thesisDTO.setProposalDate(currentDate);
With the debugger I can see that the format is changed to: "Wed Feb 16 10:49:28 CET 2022" and my webservice request cannot read it.
Converting the thesisDTO
to JSON and sending the request I do with the following code (javax.ws.rs):
Client restclient = ClientBuilder.newClient();
WebTarget target = restclient.target(url);
String response = target.request(MediaType.APPLICATION_JSON)
.accept(MediaType.TEXT_PLAIN_TYPE)
.post(Entity.json(thesisWebServiceDTO), String.class);
Has anyone an idea why the format is different and how I can change it? I can not use SimpleDateFormatter to change because that is only for displaying another format I think.
Thanks a lot, Nicole