You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Matthew Broadhead <ma...@nbmlaw.co.uk.INVALID> on 2019/08/21 09:17:21 UTC

JSON dates

Using TomEE 7.1.0 Plus

when using jax-rs endpoint the dates in my objects are getting changed 
presumably using timezone data.

for example the uk is now in summer time so the date 2019-08-17T00:00:00 
becomes 2019-08-16T23:00:00  even when i am not using the time part of 
the date.

i am using momentjs and moment(date).utc() is supposed to bring the date 
back to utc but that does not work as the json doesn't seem to include 
the original date but the recalculated date

i also tried using a date converter like
public class DateConverter implements Converter<Date> {
     @Override
     public String toString(final Date instance) {
         final Calendar cal = GregorianCalendar.getInstance();
         cal.setTime(instance);
         return DatatypeConverter.printDateTime(cal);
     }

     @Override
     public Date fromString(final String text) {
         return DatatypeConverter.parseDateTime(text).getTime();
     }
}
but it doesn't make any difference

is there any documentation on this?

Re: JSON dates

Posted by Matthew Broadhead <ma...@nbmlaw.co.uk.INVALID>.
it looks fixed if i change my converter to work like this but it is 
annoying to have to annotate every date in the DTOs.  is there a global 
setting?

public class DateConverter implements Converter<Date> {

     private static final String iso8601 = "yyyy-MM-dd'T'HH:mm:ss";

     @Override
     public String toString(final Date instance) {
         SimpleDateFormat sdf = new SimpleDateFormat(iso8601);
         String string = sdf.format(instance);
         return string;
     }

     @Override
     public Date fromString(final String text) {
         return DatatypeConverter.parseDateTime(text).getTime();
     }
}


On 21/08/2019 11:17, Matthew Broadhead wrote:
> Using TomEE 7.1.0 Plus
>
> when using jax-rs endpoint the dates in my objects are getting changed 
> presumably using timezone data.
>
> for example the uk is now in summer time so the date 
> 2019-08-17T00:00:00 becomes 2019-08-16T23:00:00  even when i am not 
> using the time part of the date.
>
> i am using momentjs and moment(date).utc() is supposed to bring the 
> date back to utc but that does not work as the json doesn't seem to 
> include the original date but the recalculated date
>
> i also tried using a date converter like
> public class DateConverter implements Converter<Date> {
>     @Override
>     public String toString(final Date instance) {
>         final Calendar cal = GregorianCalendar.getInstance();
>         cal.setTime(instance);
>         return DatatypeConverter.printDateTime(cal);
>     }
>
>     @Override
>     public Date fromString(final String text) {
>         return DatatypeConverter.parseDateTime(text).getTime();
>     }
> }
> but it doesn't make any difference
>
> is there any documentation on this?