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

Error marshalling a Groovy object #256

Closed
siaspa opened this issue Mar 28, 2019 · 1 comment · Fixed by #302
Closed

Error marshalling a Groovy object #256

siaspa opened this issue Mar 28, 2019 · 1 comment · Fixed by #302
Assignees
Milestone

Comments

@siaspa
Copy link

siaspa commented Mar 28, 2019

This example tries to marshal a simple Groovy object, but it raises the following exception

Caused by: java.lang.IllegalAccessException: Class org.eclipse.yasson.internal.model.GetFromGetter can not access a member of class sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl with modifiers "public final"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)

Maybe it's better to limit the reflection to symbols added in GroovyObject subclasses...in many cases it's what we expect to marshal.

import javax.json.bind.Jsonb
import javax.json.bind.JsonbBuilder

class Square {
    Integer size = 10;
}

class GroovyYassonBugTest {

    static void main(String[] args) {
        Square square = new Square()

        Jsonb jsonb = JsonbBuilder.create()
        String jsonString = jsonb.toJson(square);
    }
}
@aguibert
Copy link
Member

Hi @siaspa, thanks for raising this issue.

I tried to use your provided code to reproduce the issue, and I had to change Square so it was a public static inner class of the main class like this:

import javax.json.bind.Jsonb
import javax.json.bind.JsonbBuilder

class GroovyYassonBugTest {

    public static class Square {
        Integer size = 10;
    }

    static void main(String[] args) {
        Square square = new Square()

        Jsonb jsonb = JsonbBuilder.create()
        String jsonString = jsonb.toJson(square);
    }
}

From here Yasson actually attempted to serialize the object, but ran into an infinite loop that resulted in either a StackOverflowException or an OOM.

After inspecting the resulting Groovy class I see that Groovy adds in a public MetaClass getMetaClass() method which seems to be the culprit for the infinite loop. I added a special case in PR #302 to automatically ignore this method and then the code worked for me.

@aguibert aguibert added this to the 1.0.5 milestone Sep 6, 2019
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.

2 participants