Skip to content

Conversation

@theminjunchoi
Copy link

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 existing json() 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

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don't submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • 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).

Introduces JacksonJsonRedisSerializer.of(Class<T>) as a static factory method for creating serializer instances, and adds RedisSerializer.json(Class<T>) as an interface-level helper method. This simplifies RedisTemplate setup code and aligns with modern Java API design conventions.

Closes spring-projects#3252

Signed-off-by: Minjun Choi <mj043000@naver.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 16, 2025
@theminjunchoi theminjunchoi force-pushed the 3252-jacksonjsonredisserializer branch from 41fa7db to 0ee3a06 Compare November 16, 2025 16:46
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Static Factory Method for JacksonJsonRedisSerializer

4 participants