I'm using Spring Security with Spring Session which serializes the session to Redis as JSON. To make it properly working I make this Spring Session configuration. Also, I added SecurityJackson2Modules
to the Redis Jackson serializer to make it working properly with Spring Security object.
How I understand any class serialized to session with Spring Security should be marked with an annotation like @JsonTypeInfo
or @JsonSerialize
if it's not in the allowed classes list of SecurityJackson2Modules
. Classes like Date
, ArrayList
or Instant
are there but BigDecimal
is not for some reason.
How could I resolve the problem properly? Honestly I have a solution but I'm not sure if it's the most optimal.
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public class ProductDto {
private Long id;
private String name;
private String description;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type")
@JsonSubTypes({ @JsonSubTypes.Type(name = "BIG_DECIMAL", value = BigDecimal.class) })
private BigDecimal price;
// getters, setters etc.
}
UPD. Added an issue https://github.com/spring-projects/spring-security/issues/10325