F
F
foonfyrick2021-01-24 18:35:56
Kotlin
foonfyrick, 2021-01-24 18:35:56

Jackson converting to json and back to date class?

In general, I converted to json like this:

val user = User("test",999888)
val om = ObjectMapper().writeValueAsString(user)
//ошибка 
 val u2:User = ObjectMapper().readValue<User>(om,object:TypeReference<User>(){})

What they offer does not work on stackoverflow.
I can't get the data class back.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
foonfyrick, 2021-01-30
@foonfyrick

you need to add the jackson-module-kotlin dependency.
object:TypeReference(){] is not needed, just add an annotation to the @JasonCreator class constructor and each field @JasonProperty("name") .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question