Class JsonMessageRowMapper
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:
@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 Summary
ConstructorsConstructorDescriptionJsonMessageRowMapper(String @Nullable ... trustedPackages) Create a newJsonMessageRowMapperwith additional trusted packages for deserialization.JsonMessageRowMapper(JsonObjectMapper<?, ?> jsonObjectMapper) Create a newJsonMessageRowMapperwith a customJsonObjectMapper. -
Method Summary
-
Constructor Details
-
JsonMessageRowMapper
Create a newJsonMessageRowMapperwith 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 benullor empty to use only default packages
-
JsonMessageRowMapper
Create a newJsonMessageRowMapperwith a customJsonObjectMapper.This constructor allows full control over the JSON deserialization configuration.
Note: The same JsonObjectMapper configuration should be used in the corresponding
JsonChannelMessageStorePreparedStatementSetterfor consistent serialization and deserialization.- Parameters:
jsonObjectMapper- theJsonObjectMapperto use for JSON deserialization
-
-
Method Details
-
mapRow
- Specified by:
mapRowin interfaceRowMapper<Message<?>>- Throws:
SQLException
-