Skip to content
Advertisement

OffsetDateTime always converted to UTC

I’m having a very simple spring boot app that gets and returns a timestamp.

The code is as follow:

Controller

@RestController
public class DemoController {

    @PostMapping("/")
    public Model test(@RequestBody Model model) {
        return model;
    }
}

Model

public class Model {
    public OffsetDateTime timestamp;
}

I’ve noticed that when I’m sending timezones which are not UTC the object I’m receiving converted into UTC – for example, the following call:

{
    "timestamp": "2017-07-21T17:32:28+01:00"
}

has this response:

{
    "timestamp": "2017-07-21T16:32:28Z"
}

Is there a way to disable this behavior and receive the time as it was send?

Advertisement

Answer

This happens because Jackson is using context default timezone when deserializing. In Spring-Boot you can disable this quite easily, by just adding:

spring.jackson.deserialization.adjust-dates-to-context-time-zone=false

to your application.properties.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement