I’m trying to snapshot an Authentication
instance. (This is for a Quartz scheduled job.) As per documentation, I’m registering the SecurityJackson2Modules
into my object mapper. This works fine for both serialization and deserialization if I use a vanilla ObjectMapper
. If I use the Spring autoconfigured one, however, I get an exception upon deserialization from the PreAuthenticatedAuthenticationToken
class, namely at this object:
{"@class":"org.springframework.security.core.authority.SimpleGrantedAuthority","authority":"ROLE_Corporate_CLIENT"}
In the working case this gets correctly deserialized into a SimpleGrantedAuthority
while in the non-working case this results just into a HashMap
. Apparently, there’s a SimpleGrantedAuthority
mixin registered in both cases which should handle this JSON snippet, however it doesn’t trigger for some reason in the Spring autoconfigured case.
So there must be some crucial difference in the way how the Spring and vanilla ObjectMapper
s are configured. The problem is that I have no idea how to debug this kind of problem. I’ve tried to manually register the same modules to the vanilla mapper as are present in my autoconfigured one but the deserialization still kept working. After that, I ran out of ideas.