1

I've found that ObjectMapper tends to omit nullable parameters.

Following expression:

objectMapper.readValue<Pair<String?,Long?>>("{}")

causes:

caused by com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException: 
Instantiation of [simple type, class kotlin.Pair] 
value failed for JSON property first due to missing (therefore NULL) value for creator 
parameter first which is a non-nullable type at [Source: (String)"{}"; line: 1, column: 2] 
(through reference chain: kotlin.Pair["first"])

while:

data class InternalPair(val first: String?, val second: Long?)

objectMapper.readValue<InternalPair>("{}")

works fine.

Is it intended or is it a bug?

pixel
  • 24,905
  • 36
  • 149
  • 251
  • Take a look on similar question [Jackson 3rd Party Class With No Default Constructor](https://stackoverflow.com/questions/11838039/jackson-3rd-party-class-with-no-default-constructor). I guess, your `InternalPair` has optional values and can be created from empty `JSON Object`. Try to declare it like `data class InternalPair(val first: String, val second: Long)` and check what would be the output. You can implement custom deserialiser and return empty `Pair` in that case. – Michał Ziober Jan 14 '20 at 13:24
  • In `Pair` I use nullable parameters as well... – pixel Jan 20 '20 at 08:14

0 Answers0