Skip to content

Commit 631b916

Browse files
committed
Yet more tweaking wrt #4907
1 parent 836557f commit 631b916

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/main/java/tools/jackson/databind/ser/BasicSerializerFactory.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ protected ValueSerializer<?> buildContainerSerializer(SerializationContext ctxt,
520520
beanDescRef, formatOverrides, staticTyping,
521521
elementTypeSerializer, elementValueSerializer);
522522
}
523-
// With Map-like, just 2 options: (1) Custom, (2) Annotations
523+
// With Collection-like, just 2 options: (1) Custom, (2) Annotations
524524
ValueSerializer<?> ser = null;
525525
CollectionLikeType clType = (CollectionLikeType) type;
526526
for (Serializers serializers : customSerializers()) { // (1) Custom
@@ -574,18 +574,17 @@ protected ValueSerializer<?> buildCollectionSerializer(SerializationContext ctxt
574574
}
575575
}
576576

577-
JsonFormat.Value format = _calculateEffectiveFormat(ctxt,
578-
beanDescRef, Collection.class, formatOverrides);
579577
if (ser == null) {
580578
ser = findSerializerByAnnotations(ctxt, type, beanDescRef); // (2) Annotations
581579
if (ser == null) {
580+
JsonFormat.Value format = _calculateEffectiveFormat(ctxt,
581+
beanDescRef, Collection.class, formatOverrides);
582582
// We may also want to use serialize Collections "as beans", if (and only if)
583583
// shape specified as "POJO"
584584
if (format.getShape() == JsonFormat.Shape.POJO) {
585585
return null;
586586
}
587-
Class<?> raw = type.getRawClass();
588-
if (EnumSet.class.isAssignableFrom(raw)) {
587+
if (type.isTypeOrSubTypeOf(EnumSet.class)) {
589588
// this may or may not be available (Class doesn't; type of field/method does)
590589
JavaType enumType = type.getContentType();
591590
// and even if nominally there is something, only use if it really is enum
@@ -595,7 +594,7 @@ protected ValueSerializer<?> buildCollectionSerializer(SerializationContext ctxt
595594
ser = buildEnumSetSerializer(enumType);
596595
} else {
597596
Class<?> elementRaw = type.getContentType().getRawClass();
598-
if (isIndexedList(raw)) {
597+
if (isIndexedList(type.getRawClass())) {
599598
if (elementRaw == String.class) {
600599
// Only optimize if std implementation, not custom
601600
if (ClassUtil.isJacksonStdImpl(elementValueSerializer)) {
@@ -667,14 +666,6 @@ protected ValueSerializer<?> buildMapSerializer(SerializationContext ctxt,
667666
boolean staticTyping, ValueSerializer<Object> keySerializer,
668667
TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer)
669668
{
670-
JsonFormat.Value format = _calculateEffectiveFormat(ctxt,
671-
beanDescRef, Map.class, formatOverrides);
672-
673-
// [databind#467]: This is where we could allow serialization "as POJO": But! It's
674-
// nasty to undo, and does not apply on per-property basis. So, hardly optimal
675-
if (format.getShape() == JsonFormat.Shape.POJO) {
676-
return null;
677-
}
678669
ValueSerializer<?> ser = null;
679670

680671
// Order of lookups:
@@ -691,6 +682,15 @@ protected ValueSerializer<?> buildMapSerializer(SerializationContext ctxt,
691682
if (ser == null) {
692683
ser = findSerializerByAnnotations(ctxt, type, beanDescRef); // (2) Annotations
693684
if (ser == null) {
685+
JsonFormat.Value format = _calculateEffectiveFormat(ctxt,
686+
beanDescRef, Map.class, formatOverrides);
687+
688+
// [databind#467]: This is where we could allow serialization "as POJO": But! It's
689+
// nasty to undo, and does not apply on per-property basis. So, hardly optimal
690+
if (format.getShape() == JsonFormat.Shape.POJO) {
691+
return null;
692+
}
693+
694694
Object filterId = findFilterId(config, beanDescRef);
695695
// 01-May-2016, tatu: Which base type to use here gets tricky, since
696696
// most often it ought to be `Map` or `EnumMap`, but due to abstract
@@ -897,9 +897,8 @@ protected ValueSerializer<?> buildArraySerializer(SerializationContext ctxt,
897897
ValueSerializer<?> ser = null;
898898

899899
for (Serializers serializers : customSerializers()) { // (1) Custom
900-
ser = serializers.findArraySerializer(config, type, beanDescRef, formatOverrides,
901-
elementTypeSerializer, elementValueSerializer);
902-
if (ser != null) {
900+
if ((ser = serializers.findArraySerializer(config, type, beanDescRef, formatOverrides,
901+
elementTypeSerializer, elementValueSerializer)) != null) {
903902
break;
904903
}
905904
}

0 commit comments

Comments
 (0)