Skip to content

Skip serialization of groovy.lang.MetaClass values to avoid StackOverflowError  #93

@chashnikov

Description

@chashnikov

Try serializing empty Groovy class using Groovy 3.0.9 and jackson-jr-objects:2.13.1:

import com.fasterxml.jackson.jr.ob.JSON
import groovy.transform.CompileStatic

class MyBean {}

@CompileStatic
class JsonTest {
    static void main(String[] args) {
        println JSON.std.asString(new MyBean())
    }
}

It'll fail with StackOverflowError:

	at com.fasterxml.jackson.jr.ob.impl.JSONWriter.writeBeanValue(JSONWriter.java)
	at com.fasterxml.jackson.jr.ob.impl.BeanWriter.writeValue(BeanWriter.java)
	at com.fasterxml.jackson.jr.ob.impl.JSONWriter._writeValue(JSONWriter.java)
	at com.fasterxml.jackson.jr.ob.impl.JSONWriter.writeBeanValue(JSONWriter.java)
	at com.fasterxml.jackson.jr.ob.impl.BeanWriter.writeValue(BeanWriter.java)
	at com.fasterxml.jackson.jr.ob.impl.JSONWriter._writeValue(JSONWriter.java)
	at com.fasterxml.jackson.jr.ob.impl.JSONWriter.writeBeanValue(JSONWriter.java)
	at com.fasterxml.jackson.jr.ob.impl.BeanWriter.writeValue(BeanWriter.java)

This happens because every class file generated from Groovy class contains getMetaClass method, which contains data with meta-information with cyclic references inside. The method is marked with @java.beans.Transient annotation, so if serialization automatically skips such properties, the problem will be solved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions