Jankson icon indicating copy to clipboard operation
Jankson copied to clipboard

StackOverflow when serializing non-static inner class

Open halotroop2288 opened this issue 2 years ago • 1 comments

While serializing a class consisting only of nested POJOs, primitives, lists, maps and enums, this error occurs.

I wrote out the entire stucture of this file below, as one last sanity check. There's nothing very unusual.

Structure

POJO { static Logger static Jankson static File (config file)

POJO { enum (3 values, all named with @SerializedName) enum (4 values, all named with @SerializedName) 6 doubles 7 booleans String

3 methods (not annotated) } POJO { 8 ints 2 doubles 8 booleans String 2 Lists of Strings 3 enums (3 values each, all named with @SerializedName)

method (not annotated) } POJO { 2 doubles 7 booleans (nested object with custom (de)serializers has removed) } POJO { 5 booleans int }

enum (2 values, both named with @SerializedName) HashSet of enum (7 values, all named with @SerializedName) (I've tried replacing this with ArrayList too) enum (4 values, all named with @SerializedName) 3 booleans String enum (6 values, all named with @SerializedName) HashMap of enum (10 values, all named with @SerializedName) to Float enum (3 values, all named with @SerializedName)

static method (load) (not annotated) method (save) (not annotated) method (not annotated) }

Stacktrace
java.lang.StackOverflowError: null
	at java.lang.Class.privateGetDeclaredMethods(Class.java:3396) ~[?:?]
	at java.lang.Class.getDeclaredMethods(Class.java:2504) ~[?:?]
	at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:332) ~[jankson-1.2.3.jar:?]
	at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:422) ~[jankson-1.2.3.jar:?]
	at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:422) ~[jankson-1.2.3.jar:?]
	at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:445) ~[jankson-1.2.3.jar:?]
	at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:422) ~[jankson-1.2.3.jar:?]
	at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:445) ~[jankson-1.2.3.jar:?]
	at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:422) ~[jankson-1.2.3.jar:?]
	at blue.endless.jankson.impl.MarshallerImpl.serialize(MarshallerImpl.java:445) ~[jankson-1.2.3.jar:?]
	... You get the idea

halotroop2288 avatar Aug 26 '23 01:08 halotroop2288

Caused by a non-static inner class (implicit reference to super class)

halotroop2288 avatar Aug 26 '23 01:08 halotroop2288

Amazingly, this is now fixed in 2.0. Synthetic instance fields starting with this$ are the culprit, and are possible to filter out.

falkreon avatar Jun 27 '24 23:06 falkreon