Jackson deserilizer not registering in webflux with kotlin coroutines

Viewed 338

I have little problem with Jackson Deserializer. When I add annotation in class:

        @NotNull
        @JsonDeserialize(using = JsonPointDeserializer::class)
        val pharmLocation: Point,

it deserialize correctly. But i don't want to add it everywhere in my code because I'm lazy, so I added in configuration:

@Bean
    fun jacksonCustomizer(): Jackson2ObjectMapperBuilderCustomizer {
        return Jackson2ObjectMapperBuilderCustomizer { builder: Jackson2ObjectMapperBuilder ->
            builder
                    .serializerByType(Point::class.java, JsonPointSerializer())
                    .deserializerByType(Point::class.java, JsonPointDeserializer())
        }

    }

And now funny point. Serializer is working correctly, but deserializer don't. I get error, json from request looks correctly "pharmLocation":{"lat":20.0,"lng":20.0}, but on stack I see:

org.springframework.core.codec.CodecException: Type definition error: [simple type, class org.springframework.data.geo.Point]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `org.springframework.data.geo.Point` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: (org.springframework.core.io.buffer.DefaultDataBuffer$DefaultDataBufferInputStream); line: 1, column: 74] (through reference chain: *.backend.advert.request.NewAdvert["pharmLocation"])```

I think that using awaitBodyOrNull can be reason, but no idea how to deal with it.

0 Answers
Related