Skip to content

Commit

Permalink
spring-projects#3299: use postgres function convert_from() instead of…
Browse files Browse the repository at this point in the history
… encode() to insert JSON byte stream into PreparedStatement.

This works with session attributes containing special characters in the JSON blob.
  • Loading branch information
mindhaq committed Jan 7, 2025
1 parent f4cd1d0 commit 8e86689
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public class QueryCustomizer
private static final String UPDATE_SESSION_ATTRIBUTE_QUERY = """
UPDATE %TABLE_NAME%_ATTRIBUTES
SET ATTRIBUTE_BYTES = encode(?, 'escape')::jsonb
SET ATTRIBUTE_BYTES = convert_from(?, 'UTF8')::jsonb
WHERE SESSION_PRIMARY_ID = ?
AND ATTRIBUTE_NAME = ?
""";
Expand Down Expand Up @@ -309,12 +309,12 @@ public class SessionConfig {
private static final String CREATE_SESSION_ATTRIBUTE_QUERY = """
INSERT INTO %TABLE_NAME%_ATTRIBUTES (SESSION_PRIMARY_ID, ATTRIBUTE_NAME, ATTRIBUTE_BYTES)
VALUES (?, ?, encode(?, 'escape')::jsonb) <1>
VALUES (?, ?, convert_from(?, 'UTF8')::jsonb) <1>
""";
private static final String UPDATE_SESSION_ATTRIBUTE_QUERY = """
UPDATE %TABLE_NAME%_ATTRIBUTES
SET ATTRIBUTE_BYTES = encode(?, 'escape')::jsonb
SET ATTRIBUTE_BYTES = convert_from(?, 'UTF8')::jsonb
WHERE SESSION_PRIMARY_ID = ?
AND ATTRIBUTE_NAME = ?
""";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class SessionConfig implements BeanClassLoaderAware {

private static final String CREATE_SESSION_ATTRIBUTE_QUERY = """
INSERT INTO %TABLE_NAME%_ATTRIBUTES (SESSION_PRIMARY_ID, ATTRIBUTE_NAME, ATTRIBUTE_BYTES)
VALUES (?, ?, encode(?, 'escape')::jsonb)
VALUES (?, ?, convert_from(?, 'UTF8')::jsonb)
""";

private ClassLoader classLoader;
Expand Down

0 comments on commit 8e86689

Please sign in to comment.