I am trying to serializde a jpa managed class (openjpa).
This class contains a set. At runtime this set's type is org.apache.openjpa.util.java$util$LinkedHashSet$proxy (we're using openjpa).
Jackson will serialize this fine but then will fail when it comes to deserialize as this type cannot be constructed (and when using spring security's jackson config, it is not whitelisted).
So now I think the solution is to customise the serialization so it is serailized and deserialized as a more standard set. When it is deserialized it need only implement Set.
And I want to try and avoid polluting the persistent class (so want to use mixins).
The container class is the User class and it contains set of the Role class. So far I have:
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE)
public static class UserMixin {
@JsonDeserialize(as = LinkedHashSet.class, contentAs = LinkedHashSet.class)
@JsonSerialize(as = LinkedHashSet.class, contentAs = LinkedHashSet.class, typing = Typing.DYNAMIC)
private Set<Role> roles;
}
But when I run with this I get
Invalid definition for property roles (of type 'Lxxx/yyy/User;'): Can not refine serialization content type [simple type, class xxx.yyy.Role] into java.util.LinkedHashSet; types not related
And this error occurs when serializing.
So it seems like it is not honouring the set container or something.