Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializer for class 'ArrayList' is not found. #28096

Closed
pwlan opened this issue Sep 20, 2022 · 12 comments · Fixed by #28134
Closed

Serializer for class 'ArrayList' is not found. #28096

pwlan opened this issue Sep 20, 2022 · 12 comments · Fixed by #28134

Comments

@pwlan
Copy link

pwlan commented Sep 20, 2022

Describe the bug

Hi,
thanks for the fix of #23678

But it looks like this has introduced a new issue.
When using Lists, the following error ocurrs.

Serializer for class 'ArrayList' is not found.
Mark the class as @Serializable or provide the serializer explicitly.

The issue can be easily reproduced:

fun main() {
    val arrayList = ArrayList<String>()
    Json{}.encodeToString(serializer(arrayList.javaClass), arrayList) // this will fail.
}

or

    @Path("list")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    fun listHello() = listOf(Person("Jim Halpert"))

In the case of a list, the Kotlin ListSerializer needs to be used. The same applies to Sets.

Quarkus Version

Quarkus 2.12.2

Expected behavior

It should produce beautiful json.

Originally posted by @pwlan in #23678 (comment)

@gsmet
Copy link
Member

gsmet commented Sep 20, 2022

Can you provide a small reproducer?

@quarkus-bot
Copy link

quarkus-bot bot commented Sep 20, 2022

/cc @evanchooly, @geoand

@gsmet gsmet added the triage/needs-reproducer We are waiting for a reproducer. label Sep 20, 2022
@geoand
Copy link
Contributor

geoand commented Sep 20, 2022

As Guillaume mentions, a reproducer is essential here.

@pwlan
Copy link
Author

pwlan commented Sep 20, 2022

Thanks for the super fast response!

Interesting... we get it every time in our app... but are having trouble reproducing it with a fresh hello world... this might take a moment.

Otherwise, in the case of Lists, is https://github.com/quarkusio/quarkus/blob/main/extensions/resteasy-reactive/quarkus-resteasy-reactive-kotlin-serialization/runtime/src/main/kotlin/io/quarkus/kotlin/serialization/KotlinSerializationMessageBodyWriter.kt still used to serialize the data?

@geoand
Copy link
Contributor

geoand commented Sep 20, 2022

Yeah, that should be coming into play

@pwlan
Copy link
Author

pwlan commented Sep 21, 2022

Ok, we are 1 step closer. It all comes down to the KotlinSerializationMessageBodyWriter.kt.

On the Reproducer App, KotlinSerializationMessageBodyWriter#writeRsponse is callled and that works.
On our App, KotlinSerializationMessageBodyWriter#writeTo is called and that failes.
The line is 29, json.encodeToStream(serializer(o.javaClass) , o, entityStream). If o is, for example, HashArray it will fail.

So 2 questions:

  1. Any info on how to control what method is called?
  2. Should KotlinSerializationMessageBodyWriter#writeTo work if o is an Array?

@geoand
Copy link
Contributor

geoand commented Sep 21, 2022

Would you be able to try out #28134 (see this for how to build the project)?

@geoand
Copy link
Contributor

geoand commented Sep 21, 2022

Seems like some of the tests are failing, so there is more I need to look into

geoand added a commit to geoand/quarkus that referenced this issue Sep 22, 2022
@pwlan
Copy link
Author

pwlan commented Sep 22, 2022

Ok, found the culprit.

When adding "io.quarkus:quarkus-smallrye-opentracing" as a dependency KotlinSerializationMessageBodyWriter#writeTo is called, whichs fails.

I can create a reproducer later....

@geoand
Copy link
Contributor

geoand commented Oct 5, 2022

@pwlan any change you have a reproducer? It would really help in narrowing down what is going on here.

@pwlan
Copy link
Author

pwlan commented Oct 5, 2022

Of course
quarkus-issue.zip

Just run the tests.

Any other questions, just let me know.

@geoand
Copy link
Contributor

geoand commented Oct 5, 2022

Great, thanks!

@geoand geoand removed the triage/needs-reproducer We are waiting for a reproducer. label Oct 5, 2022
geoand added a commit to geoand/quarkus that referenced this issue Oct 6, 2022
geoand added a commit to geoand/quarkus that referenced this issue Oct 6, 2022
geoand added a commit to geoand/quarkus that referenced this issue Oct 6, 2022
geoand added a commit that referenced this issue Oct 6, 2022
Use proper type for serializing Kotlin response
@quarkus-bot quarkus-bot bot added this to the 2.14 - main milestone Oct 6, 2022
@gsmet gsmet modified the milestones: 2.14 - main, 2.13.2.Final Oct 10, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Oct 10, 2022
igorregis pushed a commit to igorregis/quarkus that referenced this issue Oct 16, 2022
igorregis pushed a commit to igorregis/quarkus that referenced this issue Oct 16, 2022
igorregis pushed a commit to igorregis/quarkus that referenced this issue Oct 16, 2022
igorregis pushed a commit to igorregis/quarkus that referenced this issue Oct 17, 2022
tmihalac pushed a commit to tmihalac/quarkus that referenced this issue Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants