From 86dd187e58d0cebe7a3272e2c10dc185b9d78c7f Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 10 Dec 2021 16:54:20 -0800 Subject: [PATCH] Minor tweak to #3305 impl --- .../jackson/databind/ser/BeanSerializerFactory.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java index ba3fe93f9e..1185d4aa99 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java @@ -688,18 +688,19 @@ protected List filterBeanProperties(SerializationConfig conf protected List filterUnwantedJDKProperties(SerializationConfig config, BeanDescription beanDesc, List props) { - // First, only consider something that implement `CharSequence` + // First, only consider something that implements `CharSequence` if (beanDesc.getType().isTypeOrSubTypeOf(CharSequence.class)) { - Iterator it = props.iterator(); - while (it.hasNext()) { - BeanPropertyWriter prop = it.next(); + // And only has a single property from "isEmpty()" default method + if (props.size() == 1) { + BeanPropertyWriter prop = props.get(0); // And only remove property induced by `isEmpty()` method declared // in `CharSequence` (default implementation) + // (could in theory relax this limit, probably but... should be fine) AnnotatedMember m = prop.getMember(); if ((m instanceof AnnotatedMethod) && "isEmpty".equals(m.getName()) && m.getDeclaringClass() == CharSequence.class) { - it.remove(); + props.remove(0); } } }