Skip to content

[Conversation] date objects serialization and deserialization #625

Description

@boazdavid

PR #624 add support for conversation workspaces.
A workspace has created and updated fields as in this example:

{
  "name":"my workspace",
  "created":"2017-02-01T15:28:10.145Z",
  "updated":"2017-02-01T15:28:10.145Z",
   ...
}

The following test pass green on my local computer, but is red in travis.
I suspect the problem is that my computer and travis are in different timezones. The Z symbol should indicate that the date is in UTC. Hence, the timezone should not matter.

    @Test
    public void testDateFromJson() {
        String json = "\"2017-02-01T15:28:10.145Z\"";
        Date actual = GsonSingleton.getGson().fromJson(json, Date.class);
        Date expected = new Date(1485955690145L);
        assertEquals(expected, actual);
    }

A similar issue is when serializing a date to string. the Z is missing.

    @Test
    public void testDateToJson() {
        Date date = new Date(1485955690145L);
        String actual = GsonSingleton.getGson().toJson(date);
        String expected = "\"2017-02-01T15:28:10.145Z\"";

        // expected:<...7-02-01T15:28:10.145[Z]"> but was:<...7-02-01T15:28:10.145[]">
        assertEquals(expected, actual);
    }

I suspect that the DateDeserializer does not support this date format.
see also this:
http://stackoverflow.com/questions/2201925/converting-iso-8601-compliant-string-to-java-util-date

Java-sdk = 1.8.0_25

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions