Hello everyone, I have a problem while using Jacks...
# ktor
r
Hello everyone, I have a problem while using Jackson ContentNegotiation inside Ktor. I keep getting
InvalidDefinitionException - (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
I'm installing the feature as follows:
Copy code
install(ContentNegotiation) {
            jackson {

                // Set how the dates should be handled
                dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").apply {
                    timeZone = TimeZone.getTimeZone("UTC")
                }

                // Do not serialize null values
                setSerializationInclusion(JsonInclude.Include.NON_NULL)

                // Do not worry about unknown properties, ignoring them
                configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)

                // If we receive an empty object, treat it as null
                enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)

                //accept also lowercase value in enum fields
                enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
            }
        }
Every time I do something like
call.receive<MyClass>()
I get that error. How could I resolve the issue?
m
Are you posting bad json? Have you added the KotlinModule to your objectmapper?
r
I'm sending a valid JSON and yes, the KotlinModule is included while using Jackson ContentNegotiation
m
what’s MyClass’s definition
r
Copy code
data class AcceptanceData(
    @field:JsonProperty("did") val id: Did,
    @field:JsonProperty("email") val email: String,
    @field:JsonProperty("type") val type: String,
    @field:JsonProperty("information") val information: User.Information,
    @field:JsonProperty("authentication_key_info") val authentication_key_info: APIKeyInfo,
    @field:JsonProperty("signing_key_info") val signing_key_info: APIKeyInfo,
    @field:JsonProperty("encryption_key_info") val encryption_key_info: APIKeyInfo
)
But with any definition I use, the same error is thrown. The strange this is that it works properly in one project, and errors in another one.
m
hm. Seems reasonable. Just to have another data point, try setting up jackson as in https://bitbucket.org/marshallpierce/ktor-demo/src/master/src/.
r
What do you mean by that?
m
Configure the objectmapper without using the
jackson
helper
also, try deserializing outside of the context of ktor
r
I'll try that and let you know, thanks
Apparently this problem is caused by inline classes which deserialization is not supported by Jackson at this time
m
Ah, interesting. Good to know.
That makes sense as inline classes are not present at runtime…