spring-data-redis
spring-data-redis copied to clipboard
Add static factory method for JacksonJsonRedisSerializer.
Summary
This PR adds static factory methods for JacksonJsonRedisSerializer to simplify instantiation and improve code readability.
Closes #3252
Changes
- Added
JacksonJsonRedisSerializer.of(Class<T>)as a static factory method - Added
RedisSerializer.json(Class<T>)as an interface-level helper method (overloading existingjson()method) - Added comprehensive unit tests for both factory methods
Motivation
The current API requires verbose instantiation:
JacksonJsonRedisSerializer<Person> serializer = new JacksonJsonRedisSerializer<>(Person.class);
With the new factory methods, code becomes more concise and readable:
// Using static factory method
JacksonJsonRedisSerializer<Person> serializer = JacksonJsonRedisSerializer.of(Person.class);
// Or using interface-level helper
RedisSerializer<Person> serializer = RedisSerializer.json(Person.class);
This aligns with modern Java API design conventions (e.g., Optional.of(), List.of()) and greatly simplifies typical RedisTemplate setup code.
Checklist
- [x] You have read the Spring Data contribution guidelines.
- [x] You use the code formatters provided here and have them applied to your changes. Don't submit any formatting related changes.
- [x] You submit test cases (unit or integration tests) that back your changes.
- [x] You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).