https://kotlinlang.org logo
#jackson-kotlin
Title
# jackson-kotlin
j

Joe

04/30/2021, 8:02 PM
I'm trying to construct an object from json, with some members injected via
@JacksonInject
. I've got it working like this:
Copy code
class ClassToDeserialize {
    @JacksonInject
    private val dependency: ThirdPartyUndeserializableObject? = null
    @JsonPropery
    private val simpleValue: String
    /// ... etc 
}
To avoid nullability (and since I don't really have an instance of the dependency I can assign statically), I'd like to use constructor injection instead:
Copy code
class ClassToDeserialize(
    @JacksonInject
    private val dependency: ThirdPartyUndeserializableObject
) {
    @JsonPropery
    private val simpleValue: String
    /// ... etc 
}
but doing so still results in jackson trying to manage the dependency prior to using the injected value (manifests as
Invalid definition for property
since the class isn't json deserializable due to conflicting setters within the third party class). Adding a
@JsonIgnore
doesn't appear to have any effect, either. Is there a way to do this?
fixed with
@JacksonInject(useInput = OptBoolean.FALSE)
plus a change in jackson 2.12.4: https://github.com/FasterXML/jackson-databind/pull/3146
6 Views