Could not read JSON: Cannot construct instance of `java.time.ZonedDateTime` (no Creators, like default construct, exist)

mengmeng :

I have a service that listens to a queue then maps it to a POJO. But I'm always getting this error even after setting the @Configuration of ObjectMapper

    @Bean
    public ObjectMapper objectMapper() {
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        mapper.registerModule(new JavaTimeModule());

        return mapper;
    }

My POJO:

public class ResultDto {
    private ZonedDateTime dateSent;

    private ZonedDateTime dateDeliveryReceiptReceived;

    public ResultDto() {}
}

I get this error:

Caused by: org.springframework.messaging.converter.MessageConversionException: Could not read JSON: Cannot construct instance of `java.time.ZonedDateTime` (no Creators, like default construct, exist): no String-argument constructor/factory method to deserialize from String value ('2020-08-03T11:02:51.044+0000')

Thanks in advance!

mengmeng :

Thanks for those who answered.

With the help of team mate, we discovered that the spring cloud has its own object mapper. And not the ObjectMapper directly. Since this DTO/POJO is to the message from a AWS SNS/SQS.

This should do:

@Bean
public MappingJackson2MessageConverter mappingJackson2MessageConverter(ObjectMapper objectMapper) {
    MappingJackson2MessageConverter jacksonMessageConverter = new MappingJackson2MessageConverter();
    jacksonMessageConverter.setObjectMapper(objectMapper);
    jacksonMessageConverter.setSerializedPayloadClass(String.class);
    jacksonMessageConverter.setStrictContentTypeMatch(true);
    return jacksonMessageConverter;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Cannot construct instance of `java.time.ZonedDateTime` (no Creators, like default construct, exist)

JSON parse error: Can not construct instance of class

Jackson cannot construct instance with one parameter constructor

Cannot construct instance of - Jackson

Construct class instance from class object in java

Jackson.InvalidDefinitionException: Cannot construct instance of java.time.OffsetDateTime in JUnit @BeforeEach

JSON parse error: Cannot construct instance of `com.example.greetapp.domain.User`

No Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator

How to construct ZonedDateTime from an Instant and a time string?

Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance

Android - Getting error "Cannot construct instance of (although at least one create exist)" using Retrofit

com.fasterxml.jackson.databind.exc.InvalidDefinitionException:Cannot construct instance of`java.time.Instant`(no Creators,like default construct):

Doobie cannot find or construct a Read instance for type T

JSON parse error: Cannot construct instance of `com.dto.IdDTO` (although at least one Creator exists)

Cannot construct a Read instance for type User. Type misunderstanding with Doobie in Scala

Cannot construct instance of `java.time.ZonedDateTime` (no Creators, like default construct, exist) using RabbitMQ

Spring Boot - Jersey Client - Jackson Cannot construct instance of `java.time.Instant`

Json and abstract class 'Can not construct instance'

Jackson with Generics JSON Can not construct instance of java.lang.Class

Zip4J -> java.security.ProviderException: Could not construct MacSpi instance

Could not construct instance of helper class DatabaseHelper

Could not read JSON: Cannot construct instance of `java.util.LinkedHashMap`

Spring Boot JSON parse error: Cannot construct instance of model

Cannot find or construct a Read instance for type: Option[A]

Cannot construct instance of `com.domain.User` (no Creators, like default constructor, exist): cannot deserialize from Object value

No Creators Exist: Cannot Deserialize

Many-To-One : JSON parse error Cannot construct instance

Spring controller cannot parse JSON sent from HttpClient (Cannot construct instance of `java.util.LinkedHashMap`)

Spring DTO: Cannot construct instance of <DTO interface>