title: Sending an object containing a Date field as JSON to an API the time zone seems to be changed and the time "change"
body: <p>I am working on 2 Spring Boot projects that comunicate between them (the first project call a POST API defined on the second project and send to it a DTO object in JSON format. Both the projects at the moment runs on the same machine so they should have the same timezone (I suppose...)</p>
  <p>I have a problem sending correctly a Date format. I will try to explain what I am doing and what problem I am facing.</p>
  <p>In the first project I have this <strong>DTO</strong> object:</p>
  <pre><code>import java.util.Date;
  
  import com.fasterxml.jackson.annotation.JsonFormat;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import com.fasterxml.jackson.annotation.JsonPropertyOrder;
  
  @JsonPropertyOrder(alphabetic=true)
  public class OneRowReadTrain1DTO {
      
      @JsonFormat(pattern=&quot;yyyy-MM-dd HH:mm:ss&quot;, timezone = JsonFormat.DEFAULT_TIMEZONE)
      @JsonProperty(&quot;Time_Stamp&quot;)
      private Date timeStamp;
      
      private Double v1;
      private Double v2;
      ........................................
      ........................................
      ........................................
      CONSTRUCTOR AND GETTER AND SETTER METHODS
  }
  </code></pre>
  <p>As you can see I have this timeStamp field that is annotated with this annotation to convert the field in JSON:</p>
  <pre><code>@JsonFormat(pattern=&quot;yyyy-MM-dd HH:mm:ss&quot;, timezone = JsonFormat.DEFAULT_TIMEZONE)
  </code></pre>
  <p>it should also set the <strong>default timezone</strong></p>
  <p>Then into a class of this first project I have this method that perform the POST request to the API defined in the second project:</p>
  <pre><code>@Scheduled(fixedRate=90000)
  public void insertOneRowReadTrain1Job() {
      System.out.println(&quot;COUNTER: &quot; + counter);
      
      OneRowReadTrain1DTO currentElement = excelRowAsDtoList.get(counter);
      System.out.println(&quot;CURRENT DTO: &quot; + currentElement);
      
      String insertApiUrl = baseUrl + &quot;oneRowReadTrain1/&quot;;
      try {
          uri = new URI(insertApiUrl);
      } catch (URISyntaxException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      
      ResponseEntity&lt;Integer&gt; result = restTemplate.postForEntity(uri, currentElement, Integer.class);
      
      System.out.println(&quot;result: &quot; + result);
      System.out.println(&quot;--------------------------------------------------------------------------------------------&quot;); 
      counter++;
      
  }
  </code></pre>
  <p>As you can see I am performing the API call by this line:</p>
  <pre><code>ResponseEntity&lt;Integer&gt; result = restTemplate.postForEntity(uri, currentElement, Integer.class);
  </code></pre>
  <p>Using the debugger the <strong>timeStamp</strong> field value seems to be correct, infact this field value is:</p>
  <pre><code>OneRowReadTrain1DTO [timeStamp=Sat Oct 17 06:00:14 PDT 2009, v1=6.5718506, v2=538.47812, ......]
  </code></pre>
  <p>As you can see the value of this <strong>Date</strong> field is <strong>timeStamp=Sat Oct 17 06:00:14</strong> and it is the expected value.</p>
  <p>Then the API defined in the second project is called and here I am obtaining a strange behavior with this field value.</p>
  <p>In the second project the called API is:</p>
  <pre><code>@PostMapping(value = &quot;/train/{trainName}&quot;, consumes = &quot;application/json&quot;)
  @CrossOrigin(origins = &quot;*&quot;, allowedHeaders = &quot;*&quot;)
  public int insertTrend(@PathVariable(&quot;trainName&quot;) String trainName, 
                         @RequestBody Map&lt;String, Object&gt; jsonTrainInfo) throws IOException {
      
      int result = 0;
      
      System.out.println(&quot;trainName: &quot; + trainName);
      System.out.println(&quot;JSON: &quot; + jsonTrainInfo);
      
      result = trainService.insertOneRowReadTrain(trainName, jsonTrainInfo);
      
      return result;
  }
  </code></pre>
  <p>As you can see the obtained payload is into this method parameter:</p>
  <pre><code>@RequestBody Map&lt;String, Object&gt; jsonTrainInfo
  </code></pre>
  <p>The problem is that I am obtaining something like this:</p>
  <pre><code>{Time_Stamp=2009-10-17 13:00:14, v1=6.5718506,.....}
  </code></pre>
  <p>As you can see the value of this field is: <strong>Time_Stamp=2009-10-17 13:00:14</strong> where the date section (<strong>2009-10-17</strong>) is correct but the <strong>time section</strong> is totally wrong, infact the obtained time section is <strong>13:00:14</strong> and not the expected 06:00:14 (the one that is present into the sent object).</p>
  <p>Now from what I know 6:00 PDT equals 13:00 GMT but why have I this problem? I need that the received date is in the same time zone (or am I missing something?)</p>
  <p>Why when it is received into the <strong>Map&lt;String, Object&gt; jsonTrainInfo</strong> the timezone seems to be changed?</p>
  <p>What is wrong? What am I missing? How can I try to fix this issue? I am going crazy</p>