Repository: micronaut-projects/micronaut-core
File: jackson-databind/src/main/java/io/micronaut/jackson/modules/BeanIntrospectionModule.java (Java)

Code before:

                    newBuilder.setProperties(newProperties);
                } else {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Updating {} properties with BeanIntrospection data for type: {}", properties.size(), beanClass);
                    }

                    final var newProperties = new ArrayList<>(properties);
                    var named = new LinkedHashMap<String, BeanProperty<Object, Object>>();
                    for (BeanProperty<Object, Object> beanProperty : beanProperties) {
                        if (!beanProperty.isWriteOnly()) {
                            named.put(getName(config, namingStrategy, beanProperty), beanProperty);
                        }
                    }
                    for (int i = 0; i < properties.size(); i++) {
                        final BeanPropertyWriter existing = properties.get(i);

                        final Optional<BeanProperty<Object, Object>> property = Optional.ofNullable(named.get(existing.getName()));
                        // ignore properties that are @JsonIgnore, so that we don't replace other properties of the
                        // same name
                        if (property.isPresent() &&
                            !property.get().isAnnotationPresent(JsonIgnore.class) &&
                            // we can't support XmlBeanPropertyWriter easily https://github.com/micronaut-projects/micronaut-core/issues/5907
                            !existing.getClass().getName().equals("com.fasterxml.jackson.dataformat.xml.ser.XmlBeanPropertyWriter")) { // NOSONAR
                            final UnsafeBeanProperty<Object, Object> beanProperty = (UnsafeBeanProperty<Object, Object>) property.get();
                            if (existing instanceof AnyGetterWriter anyGetterWriter) {
                                newProperties.set(i, anyGetterWriter);
                            } else {
                                newProperties.set(i, new BeanIntrospectionPropertyWriter(
                                        existing,
                                        beanProperty,
                                        existing.getSerializer(),
                                        config.getTypeFactory(),
                                        existing.getViews()
                                    )
                                );
                            }
                        } else {
                            newProperties.set(i, existing);
                        }
                    }
                    newBuilder.setProperties(newProperties);
                }
                newBuilder.setFilteredProperties(builder.getFilteredProperties());
                return newBuilder;
            }
        }
    }

    /**
     * Modifies bean deserialization.

Review comment (suggestion):
add to the if statement just above this one instead, which does the same check for XmlBeanPropertyWriter

Code after:
                        }
                    }

                    if (newBuilder.getAnyGetter() != null) {
                        // place it last
                        newProperties.add(newBuilder.getAnyGetter());
                    }
                    newBuilder.setProperties(newProperties);
                } else {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Updating {} properties with BeanIntrospection data for type: {}", properties.size(), beanClass);
                    }

                    final var newProperties = new ArrayList<>(properties);
                    var named = new LinkedHashMap<String, BeanProperty<Object, Object>>();
                    for (BeanProperty<Object, Object> beanProperty : beanProperties) {
                        if (!beanProperty.isWriteOnly()) {
                            named.put(getName(config, namingStrategy, beanProperty), beanProperty);
                        }
                    }
                    for (int i = 0; i < properties.size(); i++) {
                        final BeanPropertyWriter existing = properties.get(i);

                        final Optional<BeanProperty<Object, Object>> property = Optional.ofNullable(named.get(existing.getName()));
                        // ignore properties that are @JsonIgnore, so that we don't replace other properties of the
                        // same name
                        if (property.isPresent() &&
                            !property.get().isAnnotationPresent(JsonIgnore.class) &&
                            // we can't support XmlBeanPropertyWriter easily https://github.com/micronaut-projects/micronaut-core/issues/5907
                            !existing.getClass().getName().equals("com.fasterxml.jackson.dataformat.xml.ser.XmlBeanPropertyWriter")
                            && !(existing instanceof AnyGetterWriter)) { // NOSONAR
                            final UnsafeBeanProperty<Object, Object> beanProperty = (UnsafeBeanProperty<Object, Object>) property.get();
                            newProperties.set(i, new BeanIntrospectionPropertyWriter(
                                    existing,
                                    beanProperty,
                                    existing.getSerializer(),
                                    config.getTypeFactory(),
                                    existing.getViews()
                                )
                            );
                        } else {
                            newProperties.set(i, existing);
                        }
                    }
                    newBuilder.setProperties(newProperties);
                }
                newBuilder.setFilteredProperties(builder.getFilteredProperties());
                return newBuilder;
            }
        }
    }