Thread
#jackson-kotlin
    Dariusz Kuc

    Dariusz Kuc

    11 months ago

    Disclaimer: This is not Kotlin specific but was hoping someone here might be able to chime in

    Hello 👋 I have a code generator and I'm using custom Jackson serializers to support • optional serialization (so I can distinguish defined value, null value and no value cases, i.e. no value should not be serialized at all and field should be omitted) • custom object serializers/deserializers (e.g. ability to marshall/unmarshall
    ULocale
    object to/from basic
    en_US
    String) Above works fine when used in separation but now I'm trying to figure out a way to do both at the same time, i.e. conditionally serialize custom objects. Registering a module that configures custom serializer for given custom type seems to work but that also implies additional setup by the users of the library (i.e. auto generated code is used to communicate with server). Anyone has any ideas whether this setup could be automated? Or maybe there are alternatives that I could use without module registration? There is an SPI that could be used to auto register modules but its usage is supposedly discouraged....
    d

    dinomite

    11 months ago
    Hmm, I don’t entirely follow, but there is indeed that auto-register all modules on the classpath function. And I say you’re also right that it’s not the best thing to use, but might be appropriate in this case
    You can at least get out the module IDs after the fact (my very first Jackson contribution) https://github.com/FasterXML/jackson-databind/pull/2035
    Dariusz Kuc

    Dariusz Kuc

    11 months ago
    in order to avoid the manual setup I'm leaning towards generating additional custom optional serializer for handling those custom objects, since I already generate other classes might as well generate additional one