#JSON GSON Problem

1 messages · Page 1 of 1 (latest)

muted zenith
#

The tribes folder is part of the path to the tribe file that I want serialized.

lime epoch
#

so you dont want to include that File object in your json file?

#

gson will be default try to serialize every field it comes accross

muted zenith
#

So you're saying that because the tribes_folder file is initialized inside of the TribeData class, GSON will try to serialize tribes_folder when it serializes a TribeData object?

lime epoch
#

ye

#

if you dont want that declare it as transient

#

``private final transient File tribesFile`

muted zenith
#

Okay, it looks like it's throwing a new error now Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final int java.lang.ThreadLocal.threadLocalHashCode accessible: module java.base does not "opens java.lang" to unnamed module @109b1232

lime epoch
#

uh fuck could you sent that class again?

#

ah got it

#

at what line does it happen and whats on that line?

muted zenith
#

This is the stacktrace for that error

#

The error is referring to line 38 in the TribeCommand paste

lime epoch
#

you have a Gson field in your TribeData class

#

id recommend having ONE global gson instance cuz its heavy to instantiate

#

and make it static

#

ig its trying to serialze it

muted zenith
#

So slap one in the main class and call it from there?

lime epoch
#

ye

#

liek MyPlugin.getGsonAccess()

muted zenith
#

That worked. Thanks dude!

#

By the way, I noticed you didn't like my code formatting. What are some rules I can follow to clean up my code?

lime epoch
#

uhh use naming conventions, tribes_folder -> tribesFolder

#

and put your fields on top of your class and always give them an access modifier