https://kotlinlang.org logo
Join SlackCommunities
Powered by
# jackson-kotlin
  • e

    Eric

    01/03/2023, 5:03 PM
    is there a non-kotlin specific jackson channel somewhere?
    d
    • 2
    • 1
  • e

    Eric

    01/11/2023, 6:57 PM
    can the kotlin module be configured via
    application.yaml
    ? for example
    Copy code
    spring:
      jackson:
        kotlin:
          null-to-empty-collection: true
          null-to-empty-map: true
          null-is-same-as-default: true
  • w

    wrongwrong

    01/14/2023, 4:07 PM
    https://kotlinlang.slack.com/archives/C0BJ0GTE2/p1673712455032579
  • w

    wrongwrong

    01/21/2023, 2:15 AM
    Cross Posting. If you know how replacing
    kotlin-reflect
    with
    kotlinx-metadata-jvm
    would benefit
    jackson-module-kotlin
    users on
    Android
    , please let me know. https://kotlinlang.slack.com/archives/C0B8M7BUY/p1674267151483919
  • w

    wrongwrong

    03/19/2023, 3:19 PM
    jackson-module-kotlin 2.15.0-rc1 has been released. https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-kotlin/2.15.0-rc1 The following important changes have been made in this version • Reduction of the amount of memory consumed by the reflection cache • Fixed an issue caused by the name of is-getter (behavior change) • Removal of Kotlin 1.4 support • Scheduled deprecation of MissingKotlinParameterException For complete release notes, please see https://github.com/FasterXML/jackson-module-kotlin/blob/f66f8c4b32a64ea9e2bef45caca2ff876f8b2f6b/release-notes/VERSION-2.x#L19 Feedback and bug reports are welcome.
    🎉 1
  • w

    wrongwrong

    04/26/2023, 8:35 AM
    jackson-module-kotlin
    2.15.0 has been released. This version contains many important changes. Feedback and bug reports are welcome. https://github.com/FasterXML/jackson-module-kotlin/blob/7dd3c74313b6640724672262e8e0d19f0498de43/release-notes/VERSION-2.x#L23-L61 https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-kotlin/2.15.0
    🎉 2
  • d

    dave08

    04/27/2023, 1:27 PM
    Is there any way to use `value class`es with jackson? (Especially with Micronaut...)
    w
    d
    • 3
    • 6
  • d

    dmcg

    05/16/2023, 7:48 AM
    Hi - I’ve an issue serializing classes that implement List - can anyone help please? https://stackoverflow.com/questions/76254106/how-can-i-configure-jackson-to-write-all-fields-of-a-kotlin-data-class-that-impl
  • b

    Brian Estrada

    07/10/2023, 12:59 PM
    Hi, does anyone know if Jackson supports serialization to dot notation?
    w
    e
    • 3
    • 2
  • w

    wrongwrong

    07/17/2023, 4:42 AM
    Regarding the deserialization speed of jackson-module-kotlin, it seems to be about 1.3 ~ 1.5 times faster with 2.16 (the more arguments, the bigger the impact). https://github.com/FasterXML/jackson-module-kotlin/pull/687#issuecomment-1637365799
    🎉 1
    K 1
  • m

    Marcus Ilgner

    07/25/2023, 1:32 PM
    Hey all 👋 Does someone have experience with serialising kotlinx datetime objects? I'm currently baffled by a situation where de-serialising works just fine, but when trying to serialise the object, it yields unexpected output.
    Copy code
    data class DataPoint {
       @JsonFormat(
            shape = JsonFormat.Shape.STRING,
            pattern = "yyyy-MM-dd HH:mm:ss",
            timezone = "UTC")
        val time: Instant,
    }
    val mapper = jacksonObjectMapper()
    mapper.registerModule(JavaTimeModule())
    
    val dataPoint = DataPoint(time = Instant.parse("2001-09-09T01:46:40Z"))
    
    val encoded = mapper.writeValueAsString(dataPoint)
    assertEquals(
                "{\"time\":\"2001-09-09T01:46:40Z\"}",
                encoded,
            )
    Unfortunately the encoded value for
    time
    looks like this an object, even though the shape was set to `STRING`:
    Copy code
    {
      "time": {
        "epochSeconds": 1000000000,
        "value$kotlinx_datetime": "2001-09-09T01:46:40Z",
        "nanosecondsOfSecond": 0
      }
    }
    any ideas?
    d
    • 2
    • 1
  • w

    wrongwrong

    09/02/2023, 3:31 AM
    crossposting https://kotlinlang.slack.com/archives/C0BJ0GTE2/p1693625433592839
    👍 1
  • w

    wrongwrong

    10/09/2023, 9:42 AM
    crossposting https://kotlinlang.slack.com/archives/C0BJ0GTE2/p1696844548876259
  • j

    Jeffrey Gulbronson

    10/20/2023, 3:40 PM
    Has anyone encountered issues using data classes with
    jackson-module-kotlin
    ? I’m trying to get it to deserialize results with the Elasticsearch client, and have registered the Kotlin extension with
    registerKotlinModule
    . Unfortunately it says
    Cannot construct instance of Foo (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
    . When decompiling the class, it actually has two constructors (one private and public), which we’re not seeing in the data classes that do deserialize correctly (those only have one public constructor)
  • j

    Jeffrey Gulbronson

    10/20/2023, 3:47 PM
    It appears this is related to using an
    inline
    class for a field of the data class
  • j

    Jeffrey Gulbronson

    10/20/2023, 3:56 PM
    Ah sadly looks like it’s https://github.com/FasterXML/jackson-module-kotlin/issues/650
  • w

    wrongwrong

    10/28/2023, 4:19 PM
    In 2.17, I intend to work on improving the performance of strictNullCheck. In particular, error-related changes will be made, so if you have any suggestions, please comment on the issue. https://github.com/FasterXML/jackson-module-kotlin/issues/719
  • h

    henrik

    11/01/2023, 4:12 PM
    Has anyone any ideas on how to solve this? https://github.com/FasterXML/jackson-module-kotlin/issues/721
    w
    • 2
    • 2
  • w

    wrongwrong

    11/11/2023, 2:12 PM
    crossposting https://kotlinlang.slack.com/archives/C0BJ0GTE2/p1699711961160069
  • w

    wrongwrong

    11/20/2023, 12:23 PM
    crossposting https://kotlinlang.slack.com/archives/C8C4JTXR7/p1700482999032369
  • w

    wrongwrong

    12/02/2023, 12:52 PM
    crossposting https://kotlinlang.slack.com/archives/C0BJ0GTE2/p1701521541349329
  • y

    Yonatan Karp-Rudin

    12/11/2023, 9:13 AM
    Hi all, I'm facing an issue to upgrade from Kotlin
    1.7.x
    to version
    1.8.x
    or above because of serialization value classes inside of a data class. Let's consider the following example:
    Copy code
    @JvmInline
    value class Value(val i: Int)
    
    data class Data(val j: Value)
    
    data class Wrapper(val value: Value, val data: Data)
    When trying the following code:
    Copy code
    val objectMapper = jacksonObjectMapper()
        .setPropertyNamingStrategy(PropertyNamingStrategies.SnakeCaseStrategy())
        .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
        .registerModule(JavaTimeModule())
    
    val json = """{"i":1,"j":771}"""
    
    val deserialized = objectMapper.readValue<Wrapper>(json)
    This code execution ends up with the following error:
    (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
    . This can be resolved by adding an empty constructor to the classes, but it makes very little sense, and I'm afraid that it would be abused by other developers in the codebase... is there any alternative that I can use here to solve the issue?
    • 1
    • 1
  • w

    wrongwrong

    02/28/2024, 12:27 PM
    crossposting https://kotlinlang.slack.com/archives/C0BJ0GTE2/p1709123226873449
    🚀 1
  • p

    Pihentagy

    03/14/2024, 2:38 PM
    Hi, I am new with kotlin. Can you help me with this data mapping problem? https://kotlinlang.slack.com/archives/C0B8MA7FA/p1710426539628479
    j
    • 2
    • 1
  • p

    Pihentagy

    06/28/2024, 10:10 AM
    I am mapping a class hierarchy to a database json field (spring boot, kotlin) Should I enumerate every
    @JsonSubTypes
    by hand, of is there a convenient solution to use the class name? So how to avoid
    Copy code
    @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
    @JsonSubTypes(
            JsonSubTypes.Type(value=MyState1::class, name = "MyState1"),
    // ...
    // ...
            JsonSubTypes.Type(value= MyState99::class, name = "MyState99")
    )
    abstract class AbstractState
    Btw I don't need the class at all, I am just logging to a jsonb field, and will query it directly from db. So say, I have this hierarchy:
    Copy code
    abstract class AbstractState
    
    data class MyState(val text: String)
    and all my wish is to put
    Copy code
    {
      "text": "the text value"
    }
    to a jsonb field.
    t
    • 2
    • 2
  • j

    Johan

    09/16/2024, 5:24 PM
    I have a class with an value class and a sealed class together, and don't really understand why they fail.
    Copy code
    data class FooDto(
        val myId: MyId = MyId(),
        @JsonDeserialize(using = SealedTypeDeserializer::class)
        val type: SealedType = TypeA.FOO,
    )
    🧵 for more info Having just one of them works fine when deserializing, but together does not work. Any clue?
    w
    • 2
    • 9
  • p

    Pihentagy

    10/22/2024, 6:39 AM
    I defined a custom objectMapper with
    Copy code
    @Bean
    @Primary
    fun objectMapper(): ObjectMapper = ...
    but this objectMapper is not used when persisting an Entity. The entity has a json field, where my custom serializer would be needed. But based on the error message it seems, that hibernate is not using that serializer. How to tell hibernate to use my custom objectMapper for json fields?
    e
    • 2
    • 3
  • w

    wrongwrong

    12/29/2024, 9:42 AM
    Hello, I would like to introduce the discussion for Jackson 3. We are currently working on a major version upgrade for Jackson. This is a good opportunity to change the default functionality, so please join the discussion if you have any suggestions. https://github.com/FasterXML/jackson-future-ideas/discussions/72 I have also prepared an issue for discussion in jackson-module-kotlin as well. https://github.com/FasterXML/jackson-module-kotlin/issues/870 Personally, I would especially like to enable FAIL_ON_NULL_FOR_PRIMITIVES by default, so please vote if you agree. https://github.com/FasterXML/jackson-future-ideas/discussions/79 Thank you.
    👍 2
    • 1
    • 1
  • w

    wrongwrong

    01/19/2025, 5:35 AM
    crossposting https://kotlinlang.slack.com/archives/C2YH04E3S/p1737264882875899
    🎉 1
  • h

    Harish Pal

    02/10/2025, 11:26 AM
    I am facing one issue. The application is Kotlin + Java. I am calling a Kotlin REST Resource passing the escaped backslash in the payload. but I am getting the below error:
    Unable to Parse JSON.
    Request Payload:
    Copy code
    {
      "eventTypeId": "USR-05 \" "
    }
    REST Controller
    Copy code
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/audit/api/1/events")
    open class WriteAuditEventResource {
    	
    	@POST
        @Consumes(MediaType.APPLICATION_JSON)
        fun writeEvent(eventRequest: AuditEventRequest): Response {
            return Response.status(Response.Status.CREATED).build()
        }
    
    }
    Problem: 1. In HTTP Logs I can see that the escaped backslash is converted to double backslash (making the JSON invalid). Below are the logs:
    Copy code
    {
        "eventTypeId": "USR-05 \\" "
    }
    Copy code
    [o.e.jetty.http.HttpParser     ] - parseNext s=CONTENT HeapByteBuffer@64870bee[p=273,l=308,c=8192,r=35]={POST /aud... 35\r\n\r\n<<<{\n    "eventTypeId": "USR-05 \\" "\n}>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00} 
    [o.e.jetty.server.HttpChannel  ] - onContent HttpChannelOverHttp@f084976{s=HttpChannelState@4962b62c{s=HANDLING rs=BLOCKING os=OPEN is=IDLE awp=false se=false i=true al=1},r=1,c=false/false,a=HANDLING,uri=//localhost:8686/audit/api/1/events/,age=35} Content@2bcdd012{HeapByteBufferR@793bf03f[p=273,l=308,c=8192,r=35]={POST /aud... 35\r\n\r\n<<<{\n    "eventTypeId": "USR-05 \\" "\n}>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00}} 
    [o.e.jetty.server.HttpInput    ] - HttpInputOverHTTP@3716942e[c=0,q=0,[0]=null,s=STREAM] addContent Content@2bcdd012{HeapByteBufferR@793bf03f[p=273,l=308,c=8192,r=35]={POST /aud... 35\r\n\r\n<<<{\n    "eventTypeId": "USR-05 \\" "\n}>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00}} 
    [o.e.jetty.http.HttpParser     ] - CONTENT --> CONTENT_END 
    [o.e.jetty.server.HttpChannel  ] - onContentComplete HttpChannelOverHttp@f084976{s=HttpChannelState@4962b62c{s=HANDLING rs=BLOCKING os=OPEN is=IDLE awp=false se=false i=true al=1},r=1,c=false/false,a=HANDLING,uri=//localhost:8686/audit/api/1/events/,age=36} 
    [o.e.jetty.http.HttpParser     ] - CONTENT_END --> END
    2. In Java Servlet Filter, if I extract the request payload from HttpServlet then I am getting below string as input:
    Copy code
    {
        "eventTypeId": "USR-05 " "
    }
    StackTrace:
    Copy code
    [.JsonProcessingExceptionMapper] - Unable to process JSON ! com.fasterxml.jackson.databind.JsonMappingException: Unexpected character ('"' (code 34)): was expecting comma to separate Object entries
    !  at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: *, column: ***] (through reference chain: com.anaplan.audit.write.api.request.AuditEventRequest["eventTypeId"])
    ! at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:402)
    ! at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:361)
    ! at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1826)
    ! at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:280)
    ! at com.fasterxml.jackson.module.afterburner.deser.SuperSonicBeanDeserializer.deserialize(SuperSonicBeanDeserializer.java:155)
    ! Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('"' (code 34)): was expecting comma to separate Object entries
    !  at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 395]
    ! at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2418)
    ! at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:749)
    ! at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:673)
    ! at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextFieldName(UTF8StreamJsonParser.java:1061)
    ! at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringKeyMap(MapDeserializer.java:608)
    More Details:
    Copy code
    Kotlin Version: 1.3.0
    JDK version: 1.8
    jackson-module-kotlin: 2.8.9
    t
    • 2
    • 12