micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6k stars 1.04k forks source link

@JsonFormat not working for @Emeddable class #10930

Open cgray9 opened 5 days ago

cgray9 commented 5 days ago

Expected Behavior

For the following class I expect openTime and closeTime to serialize as "HH:mm".

@Embeddable
@Introspected
data class Hours(
    var dayOfWeek: DayOfWeek,

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm")
    var openTime: LocalTime,

    @JsonFormat(pattern = "HH:mm")
    var closeTime: LocalTime,
    var closed: Boolean = false,
    var alwaysOpen: Boolean = false
)

Actual Behaviour

However it serializes to something like [9,0] like the JsonFormat is completely ignored. I've tried the following with no luck

Steps To Reproduce

I have the following installed in build.gradle

implementation("io.micronaut:micronaut-jackson-databind")
implementation("com.fasterxml.jackson.core:jackson-databind")
runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")

Environment Information

macOS 12.6.7 jdk 17

Example Application

No response

Version

3.9.4

dstepanov commented 5 days ago

What is the connection between JSON and @Emeddable?

cgray9 commented 5 days ago

I'm not sure, maybe it being Embeddable has nothing to do with why it's not working. Regardless, the JsonFormat should work and I can't figure out what's going on. Any help would be appreciated.

dstepanov commented 5 days ago

Please create a sample project. It's not clear how is the bean being initialized etc.