@@ -79,25 +79,47 @@ public JsonValueSerializer(JavaType nominalType,
79
79
}
80
80
81
81
protected JsonValueSerializer (JsonValueSerializer src , BeanProperty property ,
82
- JsonSerializer <?> ser , boolean forceTypeInfo )
82
+ TypeSerializer vts , JsonSerializer <?> ser , boolean forceTypeInfo )
83
83
{
84
- super (src , property , src . _valueTypeSerializer , ser );
84
+ super (src , property , vts , ser );
85
85
_valueType = src ._valueType ;
86
86
_accessor = src ._accessor ;
87
87
_staticTyping = src ._staticTyping ;
88
88
_forceTypeInformation = forceTypeInfo ;
89
89
}
90
90
91
91
public JsonValueSerializer withResolved (BeanProperty property ,
92
- JsonSerializer <?> ser , boolean forceTypeInfo )
92
+ TypeSerializer vts , JsonSerializer <?> ser , boolean forceTypeInfo )
93
93
{
94
- if ((_property == property ) && (_valueSerializer == ser )
94
+ if ((_property == property )
95
+ && (_valueTypeSerializer == vts ) && (_valueSerializer == ser )
95
96
&& (forceTypeInfo == _forceTypeInformation )) {
96
97
return this ;
97
98
}
98
- return new JsonValueSerializer (this , property , ser , forceTypeInfo );
99
+ return new JsonValueSerializer (this , property , vts , ser , forceTypeInfo );
99
100
}
100
-
101
+
102
+ /*
103
+ /**********************************************************
104
+ /* Overrides
105
+ /**********************************************************
106
+ */
107
+
108
+ @ Override // since 2.12
109
+ public boolean isEmpty (SerializerProvider ctxt , Object bean ) throws IOException
110
+ {
111
+ // 31-Oct-2020, tatu: Should perhaps catch access issue here... ?
112
+ Object referenced = _accessor .getValue (bean );
113
+ if (referenced == null ) {
114
+ return true ;
115
+ }
116
+ JsonSerializer <Object > ser = _valueSerializer ;
117
+ if (ser == null ) {
118
+ ser = _findAndAddDynamic (ctxt , referenced .getClass ());
119
+ }
120
+ return ser .isEmpty (ctxt , referenced );
121
+ }
122
+
101
123
/*
102
124
/**********************************************************************
103
125
/* Post-processing
@@ -109,40 +131,44 @@ public JsonValueSerializer withResolved(BeanProperty property,
109
131
* statically figure out what the result type must be.
110
132
*/
111
133
@ Override
112
- public JsonSerializer <?> createContextual (SerializerProvider provider ,
134
+ public JsonSerializer <?> createContextual (SerializerProvider ctxt ,
113
135
BeanProperty property )
114
136
throws JsonMappingException
115
137
{
138
+ TypeSerializer vts = _valueTypeSerializer ;
139
+ if (vts != null ) {
140
+ vts = vts .forProperty (ctxt , property );
141
+ }
116
142
JsonSerializer <?> ser = _valueSerializer ;
117
143
if (ser == null ) {
118
144
// Can only assign serializer statically if the declared type is final:
119
145
// if not, we don't really know the actual type until we get the instance.
120
146
121
147
// 10-Mar-2010, tatu: Except if static typing is to be used
122
- if (_staticTyping || provider .isEnabled (MapperFeature .USE_STATIC_TYPING )
148
+ if (_staticTyping || ctxt .isEnabled (MapperFeature .USE_STATIC_TYPING )
123
149
|| _valueType .isFinal ()) {
124
150
// false -> no need to cache
125
151
/* 10-Mar-2010, tatu: Ideally we would actually separate out type
126
152
* serializer from value serializer; but, alas, there's no access
127
153
* to serializer factory at this point...
128
154
*/
129
155
// I _think_ this can be considered a primary property...
130
- ser = provider .findPrimaryPropertySerializer (_valueType , property );
156
+ ser = ctxt .findPrimaryPropertySerializer (_valueType , property );
131
157
/* 09-Dec-2010, tatu: Turns out we must add special handling for
132
158
* cases where "native" (aka "natural") type is being serialized,
133
159
* using standard serializer
134
160
*/
135
161
boolean forceTypeInformation = isNaturalTypeWithStdHandling (_valueType .getRawClass (), ser );
136
- return withResolved (property , ser , forceTypeInformation );
162
+ return withResolved (property , vts , ser , forceTypeInformation );
137
163
}
138
164
// [databind#2822]: better hold on to "property", regardless
139
165
if (property != _property ) {
140
- return withResolved (property , ser , _forceTypeInformation );
166
+ return withResolved (property , vts , ser , _forceTypeInformation );
141
167
}
142
168
} else {
143
169
// 05-Sep-2013, tatu: I _think_ this can be considered a primary property...
144
- ser = provider .handlePrimaryContextualization (ser , property );
145
- return withResolved (property , ser , _forceTypeInformation );
170
+ ser = ctxt .handlePrimaryContextualization (ser , property );
171
+ return withResolved (property , vts , ser , _forceTypeInformation );
146
172
}
147
173
return this ;
148
174
}
0 commit comments