micronaut-projects / micronaut-core

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

Jackson deserialization doesn't work in Kotlin using GraalVM #7649

Open adrienpessu opened 2 years ago

adrienpessu commented 2 years ago

Expected Behavior

The deserialization works with a JDK ./gradlew run but when I run it with GraalVM ./gradlew nativeRun I get the error :

Caused by: io.micronaut.http.codec.CodecException: Error decoding stream for type [class net.pessu.ifconfig.IfConfig]: Cannot construct instance of `com.example.ifconfig.IfConfig` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)

Actual Behaviour

It should deserialize

Steps To Reproduce

I do have a POC in a Github repository

My data class looks like this :

data class IfConfig(
  @JsonProperty("ip") val ip: String = "",
  @JsonProperty("ip_decimal") val ip_decimal: Long = 0L,
  @JsonProperty("country") val country: String = "",
  @JsonProperty("country_iso") val country_iso: String = "",
  @JsonProperty("country_eu") val country_eu: Boolean = true,
  @JsonProperty("region_name") val region_name: String = "",
  @JsonProperty("region_code") val region_code: String = "",
  @JsonProperty("zip_code") val zip_code: String = "",
  @JsonProperty("city") val city: String = "",
  @JsonProperty("latitude") val latitude: Double = 0.0,
  @JsonProperty("longitude") val longitude: Double = 0.0,
  @JsonProperty("time_zone") val time_zone: String = "",
  @JsonProperty("asn") val asn: String = "",
  @JsonProperty("asn_org") val asn_org: String = ""
)

Environment Information

Example Application

https://github.com/adrienpessu/poc-injection-native

Version

3.5.2

yawkat commented 2 years ago

try making the class @ReflectiveAccess. the bean introspection module doesn't have kotlin support yet

adrienpessu commented 2 years ago

It works with @ReflectiveAccess. Thank you @yawkat