@@ -409,6 +409,10 @@ protected JsonSerializer<Object> constructBeanOrAddOnSerializer(SerializerProvid
409
409
}
410
410
411
411
// Any properties to suppress?
412
+
413
+ // 10-Dec-2021, tatu: [databind#3305] Some JDK types need special help
414
+ // (initially, `CharSequence` with its `isEmpty()` default impl)
415
+ props = filterUnwantedJDKProperties (config , beanDesc , props );
412
416
props = filterBeanProperties (config , beanDesc , props );
413
417
414
418
// Need to allow reordering of properties to serialize
@@ -629,7 +633,7 @@ protected List<BeanPropertyWriter> findBeanProperties(SerializerProvider prov,
629
633
/* Overridable non-public methods for manipulating bean properties
630
634
/**********************************************************
631
635
*/
632
-
636
+
633
637
/**
634
638
* Overridable method that can filter out properties. Default implementation
635
639
* checks annotations class may have.
@@ -665,6 +669,36 @@ protected List<BeanPropertyWriter> filterBeanProperties(SerializationConfig conf
665
669
return props ;
666
670
}
667
671
672
+ /**
673
+ * Overridable method used to filter out specifically problematic JDK provided
674
+ * properties.
675
+ *<p>
676
+ * See issue <a href="https://github.com/FasterXML/jackson-databind/issues/3305">
677
+ * databind-3305</a> for details.
678
+ *
679
+ * @since 2.13.1
680
+ */
681
+ protected List <BeanPropertyWriter > filterUnwantedJDKProperties (SerializationConfig config ,
682
+ BeanDescription beanDesc , List <BeanPropertyWriter > props )
683
+ {
684
+ // First, only consider something that implement `CharSequence`
685
+ if (beanDesc .getType ().isTypeOrSubTypeOf (CharSequence .class )) {
686
+ Iterator <BeanPropertyWriter > it = props .iterator ();
687
+ while (it .hasNext ()) {
688
+ BeanPropertyWriter prop = it .next ();
689
+ // And only remove property induced by `isEmpty()` method declared
690
+ // in `CharSequence` (default implementation)
691
+ AnnotatedMember m = prop .getMember ();
692
+ if ((m instanceof AnnotatedMethod )
693
+ && "isEmpty" .equals (m .getName ())
694
+ && m .getDeclaringClass () == CharSequence .class ) {
695
+ it .remove ();
696
+ }
697
+ }
698
+ }
699
+ return props ;
700
+ }
701
+
668
702
/**
669
703
* Method called to handle view information for constructed serializer,
670
704
* based on bean property writers.
0 commit comments