0

I have created a rest controller using Kotlin with Micronaut framework. The response object for the controller is as below

data class TooltipSnapshot(
    val meta: Metadata,
    val fieldLabelMapping: Map<String, String>,
    val dataset: Stream<Array<String>>
)

I have used @SerdeImport(value = TooltipSnapshot::class) in the Application startup main class.

Its giving error when trying to serialize the dataset with

Stream<Array<String>> type.

16:46:11.822 [default-nioEventLoopGroup-1-2] ERROR i.m.http.server.RouteExecutor - 
Unexpected error occurred: Type cannot be null
    java.lang.NullPointerException: Type cannot be null
at java.base/java.util.Objects.requireNonNull(Objects.java:246)
at io.micronaut.core.type.DefaultArgument.<init>(DefaultArgument.java:129)
at io.micronaut.core.type.DefaultArgument.<init>(DefaultArgument.java:100)
at io.micronaut.core.type.Argument.of(Argument.java:491)
at io.micronaut.serde.support.serdes.ObjectArraySerde.createSpecific(ObjectArraySerde.java:48)

I was getting similar error for Stream<Array<Double>> as well. However on changing it to Stream<DoubleArray> things worked fine.

However in case of String I could not find any library related to StringArray so cannot use Stream as per our requirement. The response object needs to hold an Array of Array of Strings. Which i am not able to achieve it because of above error.

I am assuming there is some issue with Micronaut serializer when using it with Kotlin language.

dtolnay
  • 9,621
  • 5
  • 41
  • 62
ShivaniK
  • 3
  • 1
  • 5
  • Not sure what you are trying to do by deserializing a stream contained inside a data-classes, but you're breaking immutability concerns. This is probably not such a good idea. See the answers here - https://stackoverflow.com/questions/29103372/how-can-i-serialize-deserialize-java-util-stream-stream-using-jackson – Sheinbergon Mar 10 '23 at 14:08

0 Answers0