webcompere / model-assert

Assertions for data models
MIT License
26 stars 3 forks source link

Add module jackson-datatype-jsr310 and jackson-datatype-jdk8 #49

Closed marcussatelis closed 6 days ago

marcussatelis commented 3 months ago

Summary

Error: Java 8 date/time type java.time.LocalDate not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: ..."])

Json Examples

Simplest Input JSON

Provide the simplest JSON that can illustrate the problem/goal

{}

Simplest comparison

Provide other relevant JSON, or JSON Pointer paths

Expected green or red test

Show the simplest test code that you think should pass or fail for this to work.

// test code

Any other information?

Do you know how to fix this? PRs welcome.

ashleyfrieze commented 3 months ago

It would be useful to see your unit test code, but I'm guessing that you're asserting the json of a Java object. The default object mapper in ModelAssert has not been given the plugin to serialise Java Time objects.

You can make your own ObjectMapper to convert your Java object to JsonNode, and then use that JsonNode in the assertion instead of a raw Java Object.

ashleyfrieze commented 3 months ago

I think this is a duplicate of #41

lmartelli commented 3 weeks ago

It would be useful to see your unit test code, but I'm guessing that you're asserting the json of a Java object. The default object mapper in ModelAssert has not been given the plugin to serialise Java Time objects.

You can make your own ObjectMapper to convert your Java object to JsonNode, and then use that JsonNode in the assertion instead of a raw Java Object.

It really is not convenient. It would be nice to be able to configure the ObjectMapper in one place, instead of having to manually convert to JsonNode for each and every assertion.

ashleyfrieze commented 3 weeks ago

@lmartelli I fully understand. Do you want to propose a PR?

ashleyfrieze commented 3 weeks ago

Can be resolved by #41, I think. @lmartelli - I've got a new PR #50 - have a look at the README and feed back. I might merge this in the next few days.

ashleyfrieze commented 6 days ago

There is now a mechanism to provide a custom ObjectMapper. Use version 1.0.3 for that.