Skip to content

Commit 628eaed

Browse files
sivaprasadreddymarcusdacoregio
authored andcommitted
Improve documentation for JDBC JSON serialization.
1 parent 6e789c7 commit 628eaed

File tree

1 file changed

+22
-1
lines changed
  • spring-session-docs/modules/ROOT/pages/configuration

1 file changed

+22
-1
lines changed

spring-session-docs/modules/ROOT/pages/configuration/jdbc.adoc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,17 @@ public class QueryCustomizer
159159
DO NOTHING
160160
""";
161161
162+
private static final String UPDATE_SESSION_ATTRIBUTE_QUERY = """
163+
UPDATE %TABLE_NAME%_ATTRIBUTES
164+
SET ATTRIBUTE_BYTES = encode(?, 'escape')::jsonb
165+
WHERE SESSION_PRIMARY_ID = ?
166+
AND ATTRIBUTE_NAME = ?
167+
""";
168+
162169
@Override
163170
public void customize(JdbcIndexedSessionRepository sessionRepository) {
164171
sessionRepository.setCreateSessionAttributeQuery(CREATE_SESSION_ATTRIBUTE_QUERY);
172+
sessionRepository.setUpdateSessionAttributeQuery(UPDATE_SESSION_ATTRIBUTE_QUERY);
165173
}
166174
167175
}
@@ -230,7 +238,10 @@ public class SessionConfig implements BeanClassLoaderAware {
230238
@Bean("springSessionConversionService")
231239
public GenericConversionService springSessionConversionService(ObjectMapper objectMapper) { <1>
232240
ObjectMapper copy = objectMapper.copy(); <2>
241+
// Register Spring Security Jackson Modules
233242
copy.registerModules(SecurityJackson2Modules.getModules(this.classLoader)); <3>
243+
// Activate default typing explicitly if not using Spring Security
244+
// copy.activateDefaultTyping(copy.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
234245
GenericConversionService converter = new GenericConversionService();
235246
converter.addConverter(Object.class, byte[].class, new SerializingConverter(new JsonSerializer(copy))); <4>
236247
converter.addConverter(byte[].class, Object.class, new DeserializingConverter(new JsonDeserializer(copy))); <4>
@@ -301,9 +312,19 @@ public class SessionConfig {
301312
VALUES (?, ?, encode(?, 'escape')::jsonb) <1>
302313
""";
303314
315+
private static final String UPDATE_SESSION_ATTRIBUTE_QUERY = """
316+
UPDATE %TABLE_NAME%_ATTRIBUTES
317+
SET ATTRIBUTE_BYTES = encode(?, 'escape')::jsonb
318+
WHERE SESSION_PRIMARY_ID = ?
319+
AND ATTRIBUTE_NAME = ?
320+
""";
321+
304322
@Bean
305323
SessionRepositoryCustomizer<JdbcIndexedSessionRepository> customizer() {
306-
return (sessionRepository) -> sessionRepository.setCreateSessionAttributeQuery(CREATE_SESSION_ATTRIBUTE_QUERY);
324+
return (sessionRepository) -> {
325+
sessionRepository.setCreateSessionAttributeQuery(CREATE_SESSION_ATTRIBUTE_QUERY);
326+
sessionRepository.setUpdateSessionAttributeQuery(UPDATE_SESSION_ATTRIBUTE_QUERY);
327+
};
307328
}
308329
309330
}

0 commit comments

Comments
 (0)