FasterXML / FasterXML/jackson-databind

support ObjectType - like JavaType but without dependence on Java class introspection

Open
#3,278 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
3.7k
Forks
1.5k
Avg merge
3d 6h
Merged PRs (30d)
28

Description

**Is your feature request related to a problem? Please describe.**

Support for defining type information for Jackson serialization/deserialization in Jackson 3 that is not necessarily based on introspection of Java class fields/methods. Obviously, we would continue to support Java introspection via JavaType but this is to allow alternative ways to provide type information.

**Describe the solution you'd like**

There are not too many people complaining but one of the biggest weaknesses of jackson-module-scala is that it can't deserialize this class properly.

```
case class OptionWrapper(opt: Option[Long])
```

The problem is described in jackson-module-scala [FAQ](https://github.com/FasterXML/jackson-module-scala/wiki/FAQ#deserializing-optionint-seqint-and-other-primitive-challenges).

If you create a JavaType for this class, we end up relying on Java reflection to get the type of 'opt' field and Java reflection suffers from type erasure so the ReferenceType that we end up for 'opt' field an inner type of java.lang.Object instead of the primitive long (or as it aliased in Scala - scala.Long).

The custom deserializer we have in jackson-module-scala gets the json value and if the number is small, it converts to an Integer and if it is big, it converts to a Long. But Scala fails to unbox the Integer because it does a cast (under the hood).

I was wondering if it would be possible to have a new ObjectType where you need to explicitly provide the field type information (in jackson 3). The Scala module could use Scala implicits, macros or a Scala-aware reflection library to construct such a ObjectType instance where it could say that the type of 'opt' field is ReferenceType with inner type of Long.
ObjectType would at its simplest be something that wraps a Map where BaseType is the super type of ObjectType, JavaType and ReferenceType (but not ResolvedType which is a superclass of JavaType but is Java class specific -- but a similar API with the Java class bits removed). The key of the map is the field name.

I'd appreciate your thoughts or pointers on how this might be done with existing classes that I'm not aware of.

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.