Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0.5, 2.5.13
-
None
Description
This started to fail in Groovy 2.5.13:
import com.fasterxml.jackson.annotation.JsonInclude @Grab('com.fasterxml.jackson.core:jackson-databind:2.9.9') import com.fasterxml.jackson.databind.ObjectMapper @Grab('org.springframework:spring-web:4.3.14.RELEASE') import org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean @groovy.transform.CompileStatic final class MyObjectMapper extends ObjectMapper { MyObjectMapper() { super(mimicSpring()) } private static ObjectMapper mimicSpring() { new Jackson2ObjectMapperFactoryBean().with { serializationInclusion = JsonInclude.Include.NON_NULL // ClassCastException: org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean cannot be cast to com.fasterxml.jackson.databind.ObjectMapper defaultViewInclusion = true // include w/o view tag failOnUnknownProperties = false autoDetectGettersSetters = true autoDetectFields = false afterPropertiesSet() return object } } private static final long serialVersionUID = 2643043846851474223L } println new MyObjectMapper()
Works fine with default (dynamic) compilation.
In this case, the delegate (Jackson2ObjectMapperFactoryBean) and owner (MyObjectMapper) both supply a setter "setSerializationInclusion" and do not have a field of the same name. StaticCompilationVisitor/StaticTypeCheckingVisitor existsProperty fail to record the receiver type when visiting the setter.