I need to save and load objects from redis.
The object contains a list of GrantedAuthority (by the way), which is the interface:
public class UserAccountAuthentication implements Authentication { private List<GrantedAuthority> authorities; private boolean authenticated = true; ... }
Jackson successfully serializes the object, but does not deserialize it with the following exception:
abstract types can only be instantiated with additional type information
I know that I can specify the type by adding:
@JsonTypeInfo(
But I cannot do this in this case, because GrantedAuthority is the Spring interface, and I cannot change it.
serialized json:
{ "authorities": [ { "authority": "ROLE_NORMAL_USER" } ], "authenticated": true, "securityToken": { "expiration": 1458635906853, "token": "sxKi3Pddfewl2rgpatVE7KiSR5qGmhpGl0spiHUTLAAW8zuoLFE0VLFYcfk72VLnli66fcVmb8aK9qFavyix3bOwgp1DRGtGacPI", "roles": [ "ROLE_NORMAL_USER" ], "expired": false, "expirationDateFormatted": "2016-03-22 08:38:26.853 UTC" }, "name": "admin", "expired": false
}
abstract GrantedAuthority populated only by SimpleGrantedAuthority .
so i tried:
objectMapper.registerSubtypes(SimpleGrantedAuthority.class);
and still no luck.
source share