On Wed, Jan 10, 2018 at 3:03 PM, Birajendu Sahu <[email protected]> wrote:
> I am using com.fasterxml.jackson.core:jackson-databind gradle plugin in my
> Kotlin application to serialise my data classes in to json objects.
>
> My class looks like this:
>
> data class MyEntityClass(
>     var id: Long,
>     var name: String,
>     var description: String? = null,
>     var updatedAt: LocalDateTime,
>     var createdAt: LocalDateTime
>
> )
>
> When I serialise this class using  jackson object mapper I am getting a json
> in below format

Since `LocalDateTime` is Java 8 date/time type, and since Jackson 2.x
does not require Java 8 (runs on Java 6, compiles on Java 7),
it does not provide support directly. You need to use Java 8 date/time
module from:

https://github.com/FasterXML/jackson-modules-java8/

and artifact name is `jackson-datatype-jsr310` (for Maven dependency
or to get jar).
Module is registered with

ObjectMapper mapper = ...;
mapper.registerModule(new JavaTimeModule());

Without adding this module databind just sees a weird POJO (with
getters) and serializes it that way.

-+ Tatu +-

>
> {
>   "id" : 10,
>   "name" : "name10",
>   "description" : "description10",
>   "updatedAt" : {
>     "nano" : 148000000,
>     "year" : 2018,
>     "month" : "JANUARY",
>     "dayOfMonth" : 10,
>     "dayOfWeek" : "WEDNESDAY",
>     "dayOfYear" : 10,
>     "hour" : 22,
>     "minute" : 26,
>     "second" : 54,
>     "monthValue" : 1,
>     "chronology" : {
>       "id" : "ISO",
>       "calendarType" : "iso8601"
>     }
>   },
>   "createdAt" : {
>     "nano" : 148000000,
>     "year" : 2018,
>     "month" : "JANUARY",
>     "dayOfMonth" : 10,
>     "dayOfWeek" : "WEDNESDAY",
>     "dayOfYear" : 10,
>     "hour" : 22,
>     "minute" : 26,
>     "second" : 54,
>     "monthValue" : 1,
>     "chronology" : {
>       "id" : "ISO",
>       "calendarType" : "iso8601"
>     }
>   }
> }
>
> How do I make updatedAt and createdAt as single string entry in resulting
> json.
>
> --
> You received this message because you are subscribed to the Google Groups
> "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to