1
1
package com .fasterxml .jackson .datatype .guava .deser ;
2
2
3
3
import java .io .IOException ;
4
+ import java .util .Collection ;
4
5
6
+ import com .fasterxml .jackson .annotation .JsonFormat ;
5
7
import com .fasterxml .jackson .core .*;
6
8
import com .fasterxml .jackson .databind .*;
7
9
import com .fasterxml .jackson .databind .deser .ContextualDeserializer ;
8
- import com .fasterxml .jackson .databind .deser .std .StdDeserializer ;
10
+ import com .fasterxml .jackson .databind .deser .NullValueProvider ;
11
+ import com .fasterxml .jackson .databind .deser .std .ContainerDeserializerBase ;
9
12
import com .fasterxml .jackson .databind .jsontype .TypeDeserializer ;
10
- import com .fasterxml .jackson .databind .type .CollectionType ;
11
13
14
+ /**
15
+ * Base class for Guava-specific collection deserializers.
16
+ */
12
17
public abstract class GuavaCollectionDeserializer <T >
13
- extends StdDeserializer <T >
18
+ extends ContainerDeserializerBase <T >
14
19
implements ContextualDeserializer
15
20
{
16
21
private static final long serialVersionUID = 1L ;
17
22
18
- protected final CollectionType _containerType ;
19
-
20
23
/**
21
24
* Deserializer used for values contained in collection being deserialized;
22
25
* either assigned on constructor, or during resolve().
@@ -28,14 +31,20 @@ public abstract class GuavaCollectionDeserializer<T>
28
31
* is the type deserializer that can deserialize required type
29
32
* information
30
33
*/
31
- protected final TypeDeserializer _typeDeserializerForValue ;
32
-
33
- protected GuavaCollectionDeserializer (CollectionType type ,
34
- TypeDeserializer typeDeser , JsonDeserializer <?> deser )
34
+ protected final TypeDeserializer _valueTypeDeserializer ;
35
+
36
+ /*
37
+ /**********************************************************
38
+ /* Life-cycle
39
+ /**********************************************************
40
+ */
41
+
42
+ protected GuavaCollectionDeserializer (JavaType selfType ,
43
+ JsonDeserializer <?> deser , TypeDeserializer typeDeser ,
44
+ NullValueProvider nuller , Boolean unwrapSingle )
35
45
{
36
- super (type );
37
- _containerType = type ;
38
- _typeDeserializerForValue = typeDeser ;
46
+ super (selfType , nuller , unwrapSingle );
47
+ _valueTypeDeserializer = typeDeser ;
39
48
_valueDeserializer = deser ;
40
49
}
41
50
@@ -44,13 +53,8 @@ protected GuavaCollectionDeserializer(CollectionType type,
44
53
* instances.
45
54
*/
46
55
public abstract GuavaCollectionDeserializer <T > withResolved (
47
- TypeDeserializer typeDeser , JsonDeserializer <?> valueDeser );
48
-
49
- /*
50
- /**********************************************************
51
- /* Validation, post-processing
52
- /**********************************************************
53
- */
56
+ JsonDeserializer <?> valueDeser , TypeDeserializer typeDeser ,
57
+ NullValueProvider nuller , Boolean unwrapSingle );
54
58
55
59
/**
56
60
* Method called to finalize setup of this deserializer,
@@ -61,26 +65,47 @@ public abstract GuavaCollectionDeserializer<T> withResolved(
61
65
public JsonDeserializer <?> createContextual (DeserializationContext ctxt ,
62
66
BeanProperty property ) throws JsonMappingException
63
67
{
64
- JsonDeserializer <?> deser = _valueDeserializer ;
65
- TypeDeserializer typeDeser = _typeDeserializerForValue ;
66
- if (deser == null ) {
67
- deser = ctxt .findContextualValueDeserializer (_containerType .getContentType (), property );
68
+ Boolean unwrapSingle = findFormatFeature (ctxt , property , Collection .class ,
69
+ JsonFormat .Feature .ACCEPT_SINGLE_VALUE_AS_ARRAY );
70
+
71
+ JsonDeserializer <?> valueDeser = _valueDeserializer ;
72
+ TypeDeserializer valueTypeDeser = _valueTypeDeserializer ;
73
+ if (valueDeser == null ) {
74
+ valueDeser = ctxt .findContextualValueDeserializer (_containerType .getContentType (), property );
68
75
}
69
- if (typeDeser != null ) {
70
- typeDeser = typeDeser .forProperty (property );
76
+ if (valueTypeDeser != null ) {
77
+ valueTypeDeser = valueTypeDeser .forProperty (property );
71
78
}
72
- if (deser == _valueDeserializer && typeDeser == _typeDeserializerForValue ) {
73
- return this ;
79
+
80
+ NullValueProvider nuller = findContentNullProvider (ctxt , property , valueDeser );
81
+
82
+ if ( (unwrapSingle != _unwrapSingle )
83
+ || (nuller != _nullProvider )
84
+ || (valueDeser != _valueDeserializer )
85
+ || (valueTypeDeser != _valueTypeDeserializer )) {
86
+ return withResolved (valueDeser , valueTypeDeser , nuller , unwrapSingle );
74
87
}
75
- return withResolved (typeDeser , deser );
88
+ return this ;
89
+ }
90
+
91
+ /*
92
+ /**********************************************************
93
+ /* Base class method implementations
94
+ /**********************************************************
95
+ */
96
+
97
+ @ SuppressWarnings ("unchecked" )
98
+ @ Override
99
+ public JsonDeserializer <Object > getContentDeserializer () {
100
+ return (JsonDeserializer <Object >) _valueDeserializer ;
76
101
}
77
102
78
103
/*
79
104
/**********************************************************
80
105
/* Deserialization interface
81
106
/**********************************************************
82
107
*/
83
-
108
+
84
109
/**
85
110
* Base implementation that does not assume specific type
86
111
* inclusion mechanism. Sub-classes are expected to override
0 commit comments