Problems with jackson and java's strong encapsulation #213
-
I'm in the process of doing a major migration of my app (Java 8 to 17 and a bunch of related libraries). I'm getting a java.lang.reflect.InaccessibleObjectException when attempting a readValue() operation. Full stack trace is below, but the relevant part is:
Based on what I've read, including a discussion on this forum, the exception occurs because the method call violates strong encapsulation/java 9 module stuff. Is there a known solution to this problem? Or is work being done to correct it? The workaround I've seen suggested is to add a jvm arg I'm using databind v2.15.3. Thanks. The code that calls it is probably not very helpful, but:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
It seems like type So the access problem is more of a symptom than root cause, looking at exception you included. |
Beta Was this translation helpful? Give feedback.
@jpdbd it's just that Jackson never explicitly forces this access, so it definitely sounds more like it was due to Bean introspection. Either way, it'd be great to have a reproduction and see what exactly is going on. There's a good chance this could be handled in better way by Jackson, but likely requires targeted changes -- there's no general solution.
Except... there are 2 settings you could try changing:
MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS
, if disabled, will not try to force access so this particular failure wouldn't show. But it is quite possible other things could not work (where access forcing is needed)MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS
, if disabled, will pre…