The following code used to work on Java 11:
new Gson().toJson(new Exception())
On JDK 17 I get the following error:
Unable to make field private java.lang.String java.lang.Throwable.detailMessage accessible: module java.base does not "opens java.lang" to unnamed module @147ed70f
From reading this page, I think I could resolve it with --add-opens java.base/java.lang=ALL-UNNAMED. Is there a better way however? Perhaps with a custom de/serializer?
I had this yesterday. I was using Java 17. I went back to Java 11 and it worked fine.
I think it's because of this: https://bugs.openjdk.java.net/browse/JDK-8256358
I am lazy and using the GSON default reflection type adapter.
You have to implement your own TypeAdapter to fix it. Or perhaps use another JSON deserializer like Jackson, which I might do later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With