Skip to content

Commit 5636626

Browse files
committed
Merge branch '2.12'
2 parents 87399ad + cdd7430 commit 5636626

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java

-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ protected final JsonSerializer<?> findSerializerByAnnotations(SerializerProvider
328328
}
329329
JsonSerializer<Object> ser = findSerializerFromAnnotation(ctxt, valueAccessor);
330330
JavaType valueType = valueAccessor.getType();
331-
// note: must get different `BeanDescription` since valueType different
332331
TypeSerializer vts = ctxt.findTypeSerializer(valueType);
333332
return new JsonValueSerializer(type, valueType, /* static typing */ false,
334333
vts, ser, valueAccessor);

src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java

+39-13
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,47 @@ public JsonValueSerializer(JavaType nominalType,
7979
}
8080

8181
protected JsonValueSerializer(JsonValueSerializer src, BeanProperty property,
82-
JsonSerializer<?> ser, boolean forceTypeInfo)
82+
TypeSerializer vts, JsonSerializer<?> ser, boolean forceTypeInfo)
8383
{
84-
super(src, property, src._valueTypeSerializer, ser);
84+
super(src, property, vts, ser);
8585
_valueType = src._valueType;
8686
_accessor = src._accessor;
8787
_staticTyping = src._staticTyping;
8888
_forceTypeInformation = forceTypeInfo;
8989
}
9090

9191
public JsonValueSerializer withResolved(BeanProperty property,
92-
JsonSerializer<?> ser, boolean forceTypeInfo)
92+
TypeSerializer vts, JsonSerializer<?> ser, boolean forceTypeInfo)
9393
{
94-
if ((_property == property) && (_valueSerializer == ser)
94+
if ((_property == property)
95+
&& (_valueTypeSerializer == vts) && (_valueSerializer == ser)
9596
&& (forceTypeInfo == _forceTypeInformation)) {
9697
return this;
9798
}
98-
return new JsonValueSerializer(this, property, ser, forceTypeInfo);
99+
return new JsonValueSerializer(this, property, vts, ser, forceTypeInfo);
99100
}
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+
101123
/*
102124
/**********************************************************************
103125
/* Post-processing
@@ -109,40 +131,44 @@ public JsonValueSerializer withResolved(BeanProperty property,
109131
* statically figure out what the result type must be.
110132
*/
111133
@Override
112-
public JsonSerializer<?> createContextual(SerializerProvider provider,
134+
public JsonSerializer<?> createContextual(SerializerProvider ctxt,
113135
BeanProperty property)
114136
throws JsonMappingException
115137
{
138+
TypeSerializer vts = _valueTypeSerializer;
139+
if (vts != null) {
140+
vts = vts.forProperty(ctxt, property);
141+
}
116142
JsonSerializer<?> ser = _valueSerializer;
117143
if (ser == null) {
118144
// Can only assign serializer statically if the declared type is final:
119145
// if not, we don't really know the actual type until we get the instance.
120146

121147
// 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)
123149
|| _valueType.isFinal()) {
124150
// false -> no need to cache
125151
/* 10-Mar-2010, tatu: Ideally we would actually separate out type
126152
* serializer from value serializer; but, alas, there's no access
127153
* to serializer factory at this point...
128154
*/
129155
// I _think_ this can be considered a primary property...
130-
ser = provider.findPrimaryPropertySerializer(_valueType, property);
156+
ser = ctxt.findPrimaryPropertySerializer(_valueType, property);
131157
/* 09-Dec-2010, tatu: Turns out we must add special handling for
132158
* cases where "native" (aka "natural") type is being serialized,
133159
* using standard serializer
134160
*/
135161
boolean forceTypeInformation = isNaturalTypeWithStdHandling(_valueType.getRawClass(), ser);
136-
return withResolved(property, ser, forceTypeInformation);
162+
return withResolved(property, vts, ser, forceTypeInformation);
137163
}
138164
// [databind#2822]: better hold on to "property", regardless
139165
if (property != _property) {
140-
return withResolved(property, ser, _forceTypeInformation);
166+
return withResolved(property, vts, ser, _forceTypeInformation);
141167
}
142168
} else {
143169
// 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);
146172
}
147173
return this;
148174
}

0 commit comments

Comments
 (0)