forked from FasterXML/jackson-module-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWrapsNullableValueClassDeserializer.java
56 lines (47 loc) · 1.99 KB
/
WrapsNullableValueClassDeserializer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.fasterxml.jackson.module.kotlin;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import kotlin.jvm.JvmClassMappingKt;
import kotlin.reflect.KClass;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
/**
* An interface to be inherited by JsonDeserializer that handles value classes that may wrap nullable.
*/
// To ensure maximum compatibility with StdDeserializer, this class is written in Java.
public abstract class WrapsNullableValueClassDeserializer<D> extends StdDeserializer<D> {
protected WrapsNullableValueClassDeserializer(@NotNull KClass<?> vc) {
super(JvmClassMappingKt.getJavaClass(vc));
}
protected WrapsNullableValueClassDeserializer(@NotNull Class<?> vc) {
super(vc);
}
protected WrapsNullableValueClassDeserializer(@NotNull JavaType valueType) {
super(valueType);
}
protected WrapsNullableValueClassDeserializer(@NotNull StdDeserializer<D> src) {
super(src);
}
@Override
@NotNull
public final Class<D> handledType() {
//noinspection unchecked
return (Class<D>) super.handledType();
}
/**
* If the parameter definition is a value class that wraps a nullable and is non-null,
* and the input to JSON is explicitly null, this value is used.
* Note that this will only be called from the KotlinValueInstantiator,
* so it will not work for top-level deserialization of value classes.
*/
// It is defined so that null can also be returned so that Nulls.SKIP can be applied.
@Nullable
public abstract D getBoxedNullValue();
@Override
public abstract D deserialize(@NotNull JsonParser p, @NotNull DeserializationContext ctxt)
throws IOException, JacksonException;
}