Skip to content

Commit 2c0ed5e

Browse files
committed
Refactoring after #4409 solved
1 parent f1798b6 commit 2c0ed5e

File tree

7 files changed

+36
-25
lines changed

7 files changed

+36
-25
lines changed

src/main/java/com/fasterxml/jackson/databind/BeanDescription.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,25 @@ public AnnotatedMember findAnySetterField() {
305305
* defined by defaults and possible annotations.
306306
* Note that this may be further refined by per-property annotations.
307307
*
308+
* @since 2.17
309+
*/
310+
public abstract JsonFormat.Value findExpectedFormat();
311+
312+
/**
308313
* @since 2.1
314+
* @deprecated Since 2.17 use {@link #findExpectedFormat()}
309315
*/
310-
public abstract JsonFormat.Value findExpectedFormat(JsonFormat.Value defValue);
316+
@Deprecated // since 2.17
317+
public JsonFormat.Value findExpectedFormat(JsonFormat.Value defValue) {
318+
JsonFormat.Value v = findExpectedFormat();
319+
if (defValue == null) {
320+
return v;
321+
}
322+
if (v == null) {
323+
return defValue;
324+
}
325+
return defValue.withOverrides(v);
326+
}
311327

312328
/**
313329
* Method for finding {@link Converter} used for serializing instances

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ protected BeanDeserializerBase(BeanDeserializerBuilder builder,
251251
;
252252

253253
// Any transformation we may need to apply?
254-
final JsonFormat.Value format = beanDesc.findExpectedFormat(null);
254+
final JsonFormat.Value format = beanDesc.findExpectedFormat();
255255
_serializationShape = format.getShape();
256256

257257
_needViewProcesing = hasViews;

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ protected Map<String,List<PropertyName>> _collectAliases(Collection<SettableBean
596596
protected boolean _findCaseInsensitivity() {
597597
// 07-May-2020, tatu: First find combination of per-type config overrides (higher
598598
// precedence) and per-type annotations (lower):
599-
JsonFormat.Value format = _beanDesc.findExpectedFormat(null);
599+
JsonFormat.Value format = _beanDesc.findExpectedFormat();
600600
// and see if any of those has explicit definition; if not, use global baseline default
601601
Boolean B = format.getFeature(JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
602602
return (B == null) ? _config.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)

src/main/java/com/fasterxml/jackson/databind/deser/DeserializerCache.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ protected JsonDeserializer<?> _createDeserializer2(DeserializationContext ctxt,
406406
// Ideally we'd determine it bit later on (to allow custom handler checks)
407407
// but that won't work for other reasons. So do it here.
408408
// (read: rewrite for 3.0)
409-
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
409+
JsonFormat.Value format = beanDesc.findExpectedFormat();
410410
if (format.getShape() != JsonFormat.Shape.OBJECT) {
411411
MapLikeType mlt = (MapLikeType) type;
412412
if (mlt instanceof MapType) {
@@ -421,7 +421,7 @@ protected JsonDeserializer<?> _createDeserializer2(DeserializationContext ctxt,
421421
* (to allow custom handler checks), but that won't work for other
422422
* reasons. So do it here.
423423
*/
424-
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
424+
JsonFormat.Value format = beanDesc.findExpectedFormat();
425425
if (format.getShape() != JsonFormat.Shape.OBJECT) {
426426
CollectionLikeType clt = (CollectionLikeType) type;
427427
if (clt instanceof CollectionType) {

src/main/java/com/fasterxml/jackson/databind/introspect/BasicBeanDescription.java

+9-14
Original file line numberDiff line numberDiff line change
@@ -405,30 +405,25 @@ public AnnotatedMethod findMethod(String name, Class<?>[] paramTypes) {
405405
/**********************************************************
406406
*/
407407

408-
@Override
409-
public JsonFormat.Value findExpectedFormat(JsonFormat.Value defValue)
408+
@Override // since 2.17
409+
public JsonFormat.Value findExpectedFormat()
410410
{
411+
JsonFormat.Value format = null;
412+
411413
// 15-Apr-2016, tatu: Let's check both per-type defaults and annotations; per-type
412414
// defaults having higher precedence, so start with that
413415
if (_annotationIntrospector != null) {
414-
JsonFormat.Value v = _annotationIntrospector.findFormat(_classInfo);
415-
if (v != null) {
416-
if (defValue == null) {
417-
defValue = v;
418-
} else {
419-
defValue = defValue.withOverrides(v);
420-
}
421-
}
416+
format = _annotationIntrospector.findFormat(_classInfo);
422417
}
423418
JsonFormat.Value v = _config.getDefaultPropertyFormat(_classInfo.getRawType());
424419
if (v != null) {
425-
if (defValue == null) {
426-
defValue = v;
420+
if (format == null) {
421+
format = v;
427422
} else {
428-
defValue = defValue.withOverrides(v);
423+
format = format.withOverrides(v);
429424
}
430425
}
431-
return defValue;
426+
return format;
432427
}
433428

434429
@Override // since 2.9

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ protected final JsonSerializer<?> findSerializerByPrimaryType(SerializerProvider
467467
}
468468
if (Number.class.isAssignableFrom(raw)) {
469469
// 21-May-2014, tatu: Couple of alternatives actually
470-
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
470+
JsonFormat.Value format = beanDesc.findExpectedFormat();
471471
switch (format.getShape()) {
472472
case STRING:
473473
return ToStringSerializer.instance;
@@ -713,7 +713,7 @@ protected JsonSerializer<?> buildCollectionSerializer(SerializerProvider prov,
713713
if (ser == null) {
714714
// We may also want to use serialize Collections "as beans", if (and only if)
715715
// this is specified with `@JsonFormat(shape=Object)`
716-
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
716+
JsonFormat.Value format = beanDesc.findExpectedFormat();
717717
if (format.getShape() == JsonFormat.Shape.OBJECT) {
718718
return null;
719719
}
@@ -803,7 +803,7 @@ protected JsonSerializer<?> buildMapSerializer(SerializerProvider prov,
803803
{
804804
// [databind#467]: This is where we could allow serialization "as POJO": But! It's
805805
// nasty to undo, and does not apply on per-property basis. So, hardly optimal
806-
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
806+
JsonFormat.Value format = beanDesc.findExpectedFormat();
807807
if (format.getShape() == JsonFormat.Shape.OBJECT) {
808808
return null;
809809
}
@@ -924,7 +924,7 @@ protected JsonSerializer<?> buildMapEntrySerializer(SerializerProvider prov,
924924
// [databind#865]: Allow serialization "as POJO" -- note: to undo, declare
925925
// serialization as `Shape.NATURAL` instead; that's JSON Object too.
926926
JsonFormat.Value formatOverride = prov.getDefaultPropertyFormat(Map.Entry.class);
927-
JsonFormat.Value formatFromAnnotation = beanDesc.findExpectedFormat(null);
927+
JsonFormat.Value formatFromAnnotation = beanDesc.findExpectedFormat();
928928
JsonFormat.Value format = JsonFormat.Value.merge(formatFromAnnotation, formatOverride);
929929
if (format.getShape() == JsonFormat.Shape.OBJECT) {
930930
return null;
@@ -1202,7 +1202,7 @@ protected JsonSerializer<?> buildEnumSerializer(SerializationConfig config,
12021202
* POJO style serialization, so we must handle that special case separately;
12031203
* otherwise pass it to EnumSerializer.
12041204
*/
1205-
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
1205+
JsonFormat.Value format = beanDesc.findExpectedFormat();
12061206
if (format.getShape() == JsonFormat.Shape.OBJECT) {
12071207
// one special case: suppress serialization of "getDeclaringClass()"...
12081208
((BasicBeanDescription) beanDesc).removeProperty("declaringClass");

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected BeanSerializerBase(JavaType type, BeanSerializerBuilder builder,
128128
_anyGetterWriter = builder.getAnyGetter();
129129
_propertyFilterId = builder.getFilterId();
130130
_objectIdWriter = builder.getObjectIdWriter();
131-
final JsonFormat.Value format = builder.getBeanDescription().findExpectedFormat(null);
131+
final JsonFormat.Value format = builder.getBeanDescription().findExpectedFormat();
132132
_serializationShape = format.getShape();
133133
}
134134
}

0 commit comments

Comments
 (0)