toJson issue

250 views
Skip to first unread message

Guy Katz

unread,
Jul 6, 2023, 12:31:54 PM7/6/23
to google-gson
Hi;
I am trying to serialize to json some objects I do not ahve contrl over.
I pump into this when trying to serialize some root with many properties and sub objects... any help would be great:
trace:
"
Exception in thread "main" java.lang.reflect.InaccessibleObjectException: Unable to make field private int java.sql.Timestamp.nanos accessible: module java.sql does not "opens java.sql" to unnamed module @31525ed3
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
        at com.google.gson.internal.reflect.UnsafeReflectionAccessor.makeAccessible(UnsafeReflectionAccessor.java:44)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:159)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
        at com.google.gson.Gson.getAdapter(Gson.java:489)
        at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:56)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:127)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:245)
        at com.google.gson.Gson.toJson(Gson.java:735)
        at com.google.gson.Gson.toJson(Gson.java:714)
        at com.google.gson.Gson.toJson(Gson.java:669)
        at com.google.gson.Gson.toJson(Gson.java:649)
        at com.example.App.main(App.java:116)

"

Éamonn McManus

unread,
Jul 6, 2023, 2:29:48 PM7/6/23
to google-gson
Have you checked the Troubleshooting Guide?

Guy Katz

unread,
Jul 9, 2023, 10:04:52 AM7/9/23
to google-gson
10x you are correct.
the troubleshhoot guide states this.
creating an exclusion strategy solved this issue for me 
thanks

Reply all
Reply to author
Forward
0 new messages