@JsonDeserialize(converter = ...) does not work with Records · Issue #3297 · FasterXML/jackson-databind (original) (raw)

Describe the bug
@JsonDeserialize(converter = ...) on Record's fields isn't picked up by Jackson during deserialization. I'm using this converter to parse time without zone information into Instant field.

Version information
Jackson: 2.13, 2.13.1-SNAPSHOT
JDK: 17

To Reproduce

public class JacksonTestCase {

    public static void main(String[] args) throws JsonProcessingException {
        var objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());

        objectMapper.readValue("""
                               { "value": "test", "time": "2021-10-07T22:47:15" }
                                """, RecordEntity.class);
    }

    static record RecordEntity(
            String value,
            @JsonDeserialize(converter = InstantWithoutZoneConverter.class)
            Instant time
    ) {
    }

    static class InstantWithoutZoneConverter implements Converter<LocalDateTime, Instant> {
        @Override
        public Instant convert(LocalDateTime value) {
            return value.toInstant(ZoneOffset.UTC);
        }

        @Override
        public JavaType getInputType(TypeFactory typeFactory) {
            return typeFactory.constructType(LocalDateTime.class);
        }

        @Override
        public JavaType getOutputType(TypeFactory typeFactory) {
            return typeFactory.constructType(Instant.class);
        }
    }
}

Additional context
It looks similar to #2974 and workaround to add @JsonProperty("time") works here as well:

    static record RecordEntity(
            String value,
            @JsonProperty("time")
            @JsonDeserialize(converter = InstantWithoutZoneConverter.class)
            Instant time
    ) {
    }