FasterXML / FasterXML/jackson-future-ideas

Support parameterized type deserialization by passing JavaType to deserializer

Open
#57 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
21
Forks
3
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
I want to be able to (de)serialize objects of type `com.github.michaelbull.result.Result` which is a type I don't own and which has no Jackson annotations. I want to do custom serialization so I can communicate with services I control written in Ruby that have Json support for equivalent `Result` types, which means that I'd like to keep Java class data off the wire. I know the type parameters for the `Result` object I want to deserialize at the point in time when I call `ObjectMapper.readValue()` and pass a JavaType with that information into that call.

Because I want to deserialize multiple flavors of `Result` I instantiate multiple instances of its deserializer passing the type information for each flavor into the constructor. I cannot register these different instances with the same `ObjectMapper`, however because `SimpleDeserializers` registers deserializers based on Java `Class` objects instead of `JavaType`s.

This is a Spring application (written in Kotlin) and I would like to be able to have a singleton `ObjectMapper` that is configured for use throughout the entire application. As it stands I have no way to configure one that can deserialize multiple flavors of the same parameterized type.

**Describe the solution you'd like**
I want to receive the `JavaType` of the object to be deserialized in the `deserialize()` call, either as a new parameter or as part of the `DeserializationContext` parameter. That way I can use the same instance of the deserializer to deserialize multiple flavors of the same parameterized type by examining the reified values of those parameters at runtime.

**Usage example**
I have a toy project that illustrates what I'm trying to do except outside of the context of Spring here: https://github.com/pgoodwin/serialization-experiment

**Additional context**

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.