Getting "Java 8 date/time type `java.time.OffsetDateTime` not supported" when using ValidatedWiremockRule

Issue #341 duplicate
Tom Hombergs created an issue

I’m using a ValidatedWiremockRule to do WireMock tests that verify against an openapi.json schema:

@Rule
public WireMockRule wireMockRule = new ValidatedWireMockRule(".../.../openapi.json"");

I’m getting this exception:

java.lang.IllegalArgumentException: Java 8 date/time type `java.time.OffsetDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: java.util.LinkedHashMap["Installation"]->io.swagger.v3.oas.models.media.ObjectSchema["properties"]->java.util.LinkedHashMap["createdAt"]->io.swagger.v3.oas.models.media.DateTimeSchema["example"])

    at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:4314)
    at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:4245)
    at com.atlassian.oai.validator.schema.SchemaValidator.lambda$new$0(SchemaValidator.java:90)
    at java.base/java.util.Optional.map(Optional.java:265)
    at com.atlassian.oai.validator.schema.SchemaValidator.<init>(SchemaValidator.java:90)
    at com.atlassian.oai.validator.OpenApiInteractionValidator.<init>(OpenApiInteractionValidator.java:155)
    at com.atlassian.oai.validator.OpenApiInteractionValidator.<init>(OpenApiInteractionValidator.java:47)
    at com.atlassian.oai.validator.OpenApiInteractionValidator$Builder.build(OpenApiInteractionValidator.java:608)
    at com.atlassian.oai.validator.wiremock.OpenApiValidationListener.<init>(OpenApiValidationListener.java:62)
    at com.atlassian.oai.validator.wiremock.ValidatedWireMockRule.setupValidationListener(ValidatedWireMockRule.java:82)
    at com.atlassian.oai.validator.wiremock.ValidatedWireMockRule.<init>(ValidatedWireMockRule.java:74)
    at cloud.atlassian.fusion.dss.commitprocessor.secrets.SecretsServiceTest.<init>(SecretsServiceTest.java:51)

Probably because the default ObjectMapper that is used by Json.mapper() in SchemaValidator doesn’t have the Java 8 Date Time module configured.

For internal reference: this is happening in the DSS SecretsServiceTest after I upgraded to the latest version of swagger-request-validator (the old version didn’t work with an openapi.json). I disabled the Swagger verification for now… .

Comments (4)

  1. Robin Stocker Account Deactivated

    You can work around this by doing this in your test setup:

    Json.mapper().registerModule(new Jdk8Module());
    Json.mapper().registerModule(new JavaTimeModule());
    

    But yeah, maybe it would be a good idea for the library to either:

    1. Make it easier to configure the used object mapper (the above is a bit of a hack because it modifies the global mapper used for Swagger)
    2. Call findAndRegisterModules() automatically on the mapper, which should take care of registering the modules automatically as long as they’re on the classpath

  2. Tom Hombergs reporter

    Yup, worked after I added this to the test:

    @BeforeClass
    public static void beforeAll(){
        Json.mapper().registerModule(new Jdk8Module());
        Json.mapper().registerModule(new JavaTimeModule());
    }
    

    Thanks!

  3. Log in to comment