swagger-api / swagger-api/swagger-codegen

[Urgent] [Help wanted]JacksonJSONProvider ObjectMapper() class generated through swagger-codegen is not able to deserialize the OffsetDateTime into ISO8601 format.

Open
#9,500 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

JacksonJSONProvider ObjectMapper() class generated through swagger-codegen is not able to deserialize the OffsetDateTime into ISO8601 format.

@Provider
@Produces({MediaType.APPLICATION_JSON})
public class JacksonJsonProvider extends JacksonJaxbJsonProvider {

    public JacksonJsonProvider() {

        ObjectMapper objectMapper = new ObjectMapper()
            .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
            .registerModule(new JavaTimeModule())
//            .findAndRegisterModules()
            .setDateFormat(new RFC3339DateFormat());

        setMapper(objectMapper);
    }
}
Swagger-codegen version

1.5.18

Swagger declaration file content or url
java -jar swagger-codegen-cli.jar generate -i $file -c ${SWAGGER_CONFIG} -DdateLibrary=java8 -l jaxrs -o ${SWAGGER_OUTPUT}
Command line used for generation

swagger-generation-v1.sh

Actual Output
        "offset": {
            "totalSeconds": 0,
            "id": "Z",
            "rules": {
                "transitions": [],
                "transitionRules": [],
                "fixedOffset": true
            }
        },
        "dayOfYear": 312,
        "year": 2006,
        "month": "NOVEMBER",
        "monthValue": 11,
        "dayOfMonth": 8,
        "hour": 15,
        "minute": 57,
        "second": 0,
        "nano": 0,
        "dayOfWeek": "WEDNESDAY"
Expected Output
"2006-11-08T21:27:00.000+0000"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated JacksonJsonProvider class and the swagger-generation-v1.sh command using Swagger Codegen 1.5.18 and -DdateLibrary=java8. Reproduce the OffsetDateTime handling with the shown ObjectMapper configuration, then compare the generated JSON with the expected ISO8601 value. Done means the generated provider serializes or deserializes OffsetDateTime in the expected format.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.