0

We are using jackson serialization of the ObjectMapper in Java.

For a LocalDateTime, the code running in my local outputs the log below :

"date":"2019-11-28T18:56:00.328Z"

The same code running on jenkins produces sth else:

"date":{"offset":{"totalSeconds":0,"id":"Z","rules":{"fixedOffset":true,"transitions":[],"transitionRules":[]}},"zone":{"totalSeconds":0,"id":"Z","rules":{"fixedOffset":true,"transitions":[],"transitionRules":[]}},"dayOfWeek":"THURSDAY","dayOfYear":332,"hour":18,"minute":46,"second":55,"nano":948000000,"year":2019,"month":"NOVEMBER","dayOfMonth":28,"monthValue":11,"chronology":{"calendarType":"iso8601","id":"ISO"}}

In the app start up we do the following:

        Json.mapper.findAndRegisterModules();
        Json.mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        Json.mapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true);
        Json.mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);

and the dependencies in the pom.xml are

        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.6.5</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.4</version>
        </dependency>

EDIT:

The jenkins machine has a different locale/timezone

Orkun
  • 6,998
  • 8
  • 56
  • 103
  • I seriously doubt that a `LocalDateTime` would output with a `Z` at the end, or itemize with an `offset` field. – Andreas Nov 28 '19 at 20:01
  • 2
    Any reason you're using `jackson-datatype-jsr310` version 2.6.5, when the rest of Jackson dependencies are version 2.9.4? Change `jackson-datatype-jsr310` to version 2.9.4 too. You can then remove the other 3, since they are transitive dependencies. – Andreas Nov 28 '19 at 20:05
  • idk if this helps... https://stackoverflow.com/questions/58809573/how-to-serialize-java-zoneddatetime-to-xml-file/58822139 – emsiiggy Nov 28 '19 at 20:35

0 Answers0