title: Cannot deserialize value of type `java.time.OffsetDateTime` from String in openapi client
body: <p>I have a spring boot application with a java client generated via the gradle plugin:</p>
  <pre><code>openApiGenerate {
      generatorName = &quot;java&quot;
      inputSpec = specsYml
      outputDir = &quot;$buildDir/generated&quot;.toString()
      apiPackage = &quot;com.customapi.api&quot;
      invokerPackage = &quot;com.customapi.invoker&quot;
      modelPackage = &quot;com.customapi.model&quot;
      configOptions = [
          dateLibrary: &quot;java8&quot;,
          library    : &quot;resttemplate&quot;
      ]
  }
  </code></pre>
  <p>I have chosen <code>&quot;java8&quot;</code> as <code>dateLibrary</code> as that seems to be the preferred one for a project with java 1.8.</p>
  <p>With that generated client I'm executing a request that returns an object that holds a timestamp.
  I get the following error:</p>
  <pre><code>java.lang.IllegalStateException: Failed to execute CommandLineRunner
      ...
  Caused by: org.springframework.web.client.RestClientException: Error while extracting response for type [class com.customapi.model.Info] and content type [application/json];
      ...
  Caused by: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.time.OffsetDateTime` from String &quot;2020-07-21T12:12:23.000+0200&quot;: ...
     ...
  ...
  Caused by: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.OffsetDateTime` from String &quot;2020-07-21T12:12:23.000+0200&quot;: Failed to deserialize java.time.OffsetDateTime: (java.time.format.DateTimeParseException) Text '2020-07-21T12:12:23.000+0200' could not be parsed at index 23
   at [Source: (ByteArrayInputStream); line: 1, column: 84] (through reference chain: com.customapi.model.Info[&quot;buildTimestamp&quot;])
      at com.fasterxml.jackson.databind.exc.InvalidFormatException.from(InvalidFormatException.java:67) ~[jackson-databind-2.10.3.jar:2.10.3]
      at com.fasterxml.jackson.databind.DeserializationContext.weirdStringException(DeserializationContext.java:1679) ~[jackson-databind-2.10.3.jar:2.10.3]
      at com.fasterxml.jackson.databind.DeserializationContext.handleWeirdStringValue(DeserializationContext.java:935) ~[jackson-databind-2.10.3.jar:2.10.3]
      at com.fasterxml.jackson.datatype.jsr310.deser.JSR310DeserializerBase._handleDateTimeException(JSR310DeserializerBase.java:86) ~[jackson-datatype-jsr310-2.10.3.jar:2.10.3]
      at com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer.deserialize(InstantDeserializer.java:218) ~[jackson-datatype-jsr310-2.10.3.jar:2.10.3]
      at com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer.deserialize(InstantDeserializer.java:50) ~[jackson-datatype-jsr310-2.10.3.jar:2.10.3]
      at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129) ~[jackson-databind-2.10.3.jar:2.10.3]
      at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:369) ~[jackson-databind-2.10.3.jar:2.10.3]
      at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159) ~[jackson-databind-2.10.3.jar:2.10.3]
      at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4218) ~[jackson-databind-2.10.3.jar:2.10.3]
      at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3267) ~[jackson-databind-2.10.3.jar:2.10.3]
      at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:269) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      ... 17 common frames omitted
  Caused by: java.time.format.DateTimeParseException: Text '2020-07-21T12:12:23.000+0200' could not be parsed at index 23
      at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) ~[na:1.8.0_151]
      at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1777) ~[na:1.8.0_151]
      at com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer.deserialize(InstantDeserializer.java:212) ~[jackson-datatype-jsr310-2.10.3.jar:2.10.3]
      ... 24 common frames omitted
  
  </code></pre>
  <p>The relevant parts of the <code>Info</code> class in question:</p>
  <pre><code>...
  @javax.annotation.Generated(value = &quot;org.openapitools.codegen.languages.JavaClientCodegen&quot;, date = &quot;2020-07-26T14:09:54.137+02:00[Europe/Berlin]&quot;)
  public class Info {
      ...
      public static final String JASON_PROPERTY_BUILD_TIMESTAMP = &quot;buildTimestamp&quot;;
      private OffsetDateTime buildTimestamp;
      ...
      public Info buildTimestamp(OffsetDateTime buildTimestamp) {
          this.buildTimestamp = buildTimestamp;
          return this;
      }
  
      public void setBuildTimestamp(OffsetDateTime buildTimestamp) {
          this.buildTimestamp = buildTimestamp;
      }
      ...
  }
  </code></pre>
  <p>Both setter methods accept <code>OffsetDateTime</code> objects and have no annotations so the conversion must happen elsewhere. The input String again is &quot;2020-07-21T12:12:23.000+0200&quot;.
  relevant dependencies are</p>
  <pre><code>ext {
      swagger_annotations_version = &quot;1.5.22&quot;
      jackson_version = &quot;2.10.3&quot;
      jackson_databind_version = &quot;2.10.3&quot;
      jackson_databind_nullable_version = &quot;0.2.1&quot;
  }
  
  dependencies {
      compile &quot;io.swagger:swagger-annotations:$swagger_annotations_version&quot;
      compile &quot;com.fasterxml.jackson.core:jackson-core:$jackson_version&quot;
      compile &quot;com.fasterxml.jackson.core:jackson-annotations:$jackson_version&quot;
      compile &quot;com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version&quot;
      compile &quot;com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version&quot;
      compile &quot;org.openapitools:jackson-databind-nullable:$jackson_databind_nullable_version&quot;
      compile &quot;com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version&quot;
  }
  </code></pre>
  <p>There seem to be a lot of problems with jackson and java 8 and most solutions on this site seem to be adding annotations. But I doubt that modifying generated code is the proper solution. Did I overlook an important parameter when generating the client? Does the server supply the wrong format? How can I investigate this?</p>
  <h2>Update:</h2>
  <p>When I switch <code>dateLibrary</code> to <code>legacy</code> it works, so I think I receive the correct data.</p>
  <p>There is a bug in the (jaxrs) server generator <a href="https://github.com/swagger-api/swagger-codegen/issues/3648#issuecomment-244056314" rel="nofollow noreferrer">https://github.com/swagger-api/swagger-codegen/issues/3648#issuecomment-244056314</a>  that has the server send out wrongly formatted (without colon) <code>date-time</code>. My solution was to use the legacy dateLibrary for the client which can handle the wrong format.</p>