[Java][Webclient] Unable to deserialize OffsetDateTime
Created by: marcoreni
Description
If we declare a date-time string, the deserialization causes an exception:
Type definition error: [simple type, class java.time.OffsetDateTime]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `java.time.OffsetDateTime` (no Creators, like default construct, exist): no String-argument constructor/factory method to deserialize from String value ('2018-08-27T15:13:30.892Z')
openapi-generator version
3.2.3-SNAPSHOT
OpenAPI declaration file content or url
openapi: 3.0.0
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
'200':
description: A paged array of pets
headers:
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
lastUpdate:
type: string
format: date-time
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Suggest a fix/enhancement
Jackson jsr310 module is listed as a dependency but it's not registered inside the objectMapper instance.
We should add:
mapper.registerModule(new JavaTimeModule());
mapper.findAndRegisterModules();
during buildWebClient()
as stated in https://github.com/FasterXML/jackson-modules-java8#registering-modules (see the warning)
Will submit a PR soon.