Class JsonMessageRowMapper

java.lang.Object
org.springframework.integration.jdbc.store.channel.JsonMessageRowMapper
All Implemented Interfaces:
RowMapper<Message<?>>

public class JsonMessageRowMapper extends Object implements RowMapper<Message<?>>
A RowMapper implementation that deserializes Message objects from JSON format stored in the database.

This mapper works in conjunction with JsonChannelMessageStorePreparedStatementSetter to provide JSON serialization for Spring Integration's JDBC Channel Message Store.

Unlike the default MessageRowMapper which uses Java serialization, this implementation uses JSON to deserialize message strings from the MESSAGE_CONTENT column.

The underlying JsonObjectMapper validates all deserialized classes against a trusted package list to prevent security vulnerabilities.

Usage Example:


 &#64;Bean
 JdbcChannelMessageStore messageStore(DataSource dataSource) {
     JdbcChannelMessageStore store = new JdbcChannelMessageStore(dataSource);
     store.setChannelMessageStoreQueryProvider(new PostgresChannelMessageStoreQueryProvider());

     // Enable JSON serialization
     store.setPreparedStatementSetter(
         new JsonChannelMessageStorePreparedStatementSetter());
     store.setMessageRowMapper(
         new JsonMessageRowMapper("com.example"));

     return store;
 }
 
Since:
7.0
Author:
Yoobin Yoon
  • Constructor Details

    • JsonMessageRowMapper

      public JsonMessageRowMapper(String @Nullable ... trustedPackages)
      Create a new JsonMessageRowMapper with additional trusted packages for deserialization.

      The provided packages are appended to the default trusted packages, enabling deserialization of custom payload types while maintaining security. If no packages are provided, only the default trusted packages are used.

      Parameters:
      trustedPackages - the additional packages to trust for deserialization. Can be null or empty to use only default packages
    • JsonMessageRowMapper

      public JsonMessageRowMapper(JsonObjectMapper<?,?> jsonObjectMapper)
      Create a new JsonMessageRowMapper with a custom JsonObjectMapper.

      This constructor allows full control over the JSON deserialization configuration.

      Note: The same JsonObjectMapper configuration should be used in the corresponding JsonChannelMessageStorePreparedStatementSetter for consistent serialization and deserialization.

      Parameters:
      jsonObjectMapper - the JsonObjectMapper to use for JSON deserialization
  • Method Details