From a2f92c0f5719f6de7811ca48aa8f7d253c4f2823 Mon Sep 17 00:00:00 2001 From: Vlad Mihalcea Date: Sun, 10 Apr 2022 20:49:11 +0300 Subject: [PATCH] Change JsonBinarySqlTypeDescriptor to bind the JSON object as String #423 --- .../type/json/internal/JsonBinarySqlTypeDescriptor.java | 4 +--- .../type/json/internal/JsonBinarySqlTypeDescriptor.java | 4 +--- .../type/json/internal/JsonBinarySqlTypeDescriptor.java | 5 ++--- .../type/json/internal/JsonBinarySqlTypeDescriptor.java | 5 ++--- .../type/json/PostgreSQLJsonStringPropertyTest.java | 5 ++--- .../type/json/internal/JsonBinarySqlTypeDescriptor.java | 5 ++--- .../type/json/PostgreSQLJsonStringPropertyTest.java | 5 ++--- .../type/json/internal/JsonBinaryJdbcTypeDescriptor.java | 5 ++--- .../type/json/PostgreSQLJsonStringPropertyTest.java | 5 ++--- 9 files changed, 16 insertions(+), 27 deletions(-) diff --git a/hibernate-types-4/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java b/hibernate-types-4/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java index 380eafe44..858265517 100644 --- a/hibernate-types-4/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java +++ b/hibernate-types-4/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java @@ -1,12 +1,10 @@ package com.vladmihalcea.hibernate.type.json.internal; -import com.fasterxml.jackson.databind.JsonNode; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.sql.BasicBinder; -import java.sql.CallableStatement; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -22,7 +20,7 @@ public ValueBinder getBinder(final JavaTypeDescriptor javaTypeDescript return new BasicBinder(javaTypeDescriptor, this) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { - st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType()); + st.setObject(index, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType()); } }; } diff --git a/hibernate-types-43/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java b/hibernate-types-43/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java index 380eafe44..858265517 100644 --- a/hibernate-types-43/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java +++ b/hibernate-types-43/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java @@ -1,12 +1,10 @@ package com.vladmihalcea.hibernate.type.json.internal; -import com.fasterxml.jackson.databind.JsonNode; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.sql.BasicBinder; -import java.sql.CallableStatement; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -22,7 +20,7 @@ public ValueBinder getBinder(final JavaTypeDescriptor javaTypeDescript return new BasicBinder(javaTypeDescriptor, this) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { - st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType()); + st.setObject(index, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType()); } }; } diff --git a/hibernate-types-5/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java b/hibernate-types-5/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java index 7e476c42e..f7e545718 100644 --- a/hibernate-types-5/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java +++ b/hibernate-types-5/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java @@ -1,6 +1,5 @@ package com.vladmihalcea.hibernate.type.json.internal; -import com.fasterxml.jackson.databind.JsonNode; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -22,13 +21,13 @@ public ValueBinder getBinder(final JavaTypeDescriptor javaTypeDescript return new BasicBinder(javaTypeDescriptor, this) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { - st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType()); + st.setObject(index, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType()); } @Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { - st.setObject(name, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType()); + st.setObject(name, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType()); } }; } diff --git a/hibernate-types-52/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java b/hibernate-types-52/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java index 7e476c42e..f7e545718 100644 --- a/hibernate-types-52/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java +++ b/hibernate-types-52/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java @@ -1,6 +1,5 @@ package com.vladmihalcea.hibernate.type.json.internal; -import com.fasterxml.jackson.databind.JsonNode; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -22,13 +21,13 @@ public ValueBinder getBinder(final JavaTypeDescriptor javaTypeDescript return new BasicBinder(javaTypeDescriptor, this) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { - st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType()); + st.setObject(index, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType()); } @Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { - st.setObject(name, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType()); + st.setObject(name, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType()); } }; } diff --git a/hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java b/hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java index 6015616bc..78b54167f 100644 --- a/hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java +++ b/hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java @@ -1,6 +1,5 @@ package com.vladmihalcea.hibernate.type.json; -import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonNode; import com.vladmihalcea.hibernate.util.AbstractPostgreSQLIntegrationTest; import com.vladmihalcea.hibernate.util.ExceptionUtil; @@ -152,8 +151,8 @@ public void testInvalidJson() { }); fail("An invalid JSON should throw an exception!"); } catch (Exception e) { - JsonParseException rootCause = ExceptionUtil.rootCause(e); - assertTrue(rootCause.getMessage().contains("Unexpected character (':'")); + Exception rootCause = ExceptionUtil.rootCause(e); + assertTrue(rootCause.getMessage().contains("invalid input syntax for type json")); } } diff --git a/hibernate-types-55/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java b/hibernate-types-55/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java index 7e476c42e..f7e545718 100644 --- a/hibernate-types-55/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java +++ b/hibernate-types-55/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java @@ -1,6 +1,5 @@ package com.vladmihalcea.hibernate.type.json.internal; -import com.fasterxml.jackson.databind.JsonNode; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -22,13 +21,13 @@ public ValueBinder getBinder(final JavaTypeDescriptor javaTypeDescript return new BasicBinder(javaTypeDescriptor, this) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { - st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType()); + st.setObject(index, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType()); } @Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { - st.setObject(name, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType()); + st.setObject(name, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType()); } }; } diff --git a/hibernate-types-55/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java b/hibernate-types-55/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java index ca17f535e..345e3e3c1 100644 --- a/hibernate-types-55/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java +++ b/hibernate-types-55/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java @@ -1,6 +1,5 @@ package com.vladmihalcea.hibernate.type.json; -import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonNode; import com.vladmihalcea.hibernate.util.AbstractPostgreSQLIntegrationTest; import com.vladmihalcea.hibernate.util.ExceptionUtil; @@ -152,8 +151,8 @@ public void testInvalidJson() { }); fail("An invalid JSON should throw an exception!"); } catch (Exception e) { - JsonParseException rootCause = ExceptionUtil.rootCause(e); - assertTrue(rootCause.getMessage().contains("Unexpected character (':'")); + Exception rootCause = ExceptionUtil.rootCause(e); + assertTrue(rootCause.getMessage().contains("invalid input syntax for type json")); } } diff --git a/hibernate-types-60/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinaryJdbcTypeDescriptor.java b/hibernate-types-60/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinaryJdbcTypeDescriptor.java index dfda74f73..89f978c43 100644 --- a/hibernate-types-60/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinaryJdbcTypeDescriptor.java +++ b/hibernate-types-60/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinaryJdbcTypeDescriptor.java @@ -1,6 +1,5 @@ package com.vladmihalcea.hibernate.type.json.internal; -import com.fasterxml.jackson.databind.JsonNode; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.JavaType; @@ -22,13 +21,13 @@ public ValueBinder getBinder(final JavaType javaType) { return new BasicBinder(javaType, this) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { - st.setObject(index, javaType.unwrap(value, JsonNode.class, options), getJdbcTypeCode()); + st.setObject(index, javaType.unwrap(value, String.class, options), getJdbcTypeCode()); } @Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { - st.setObject(name, javaType.unwrap(value, JsonNode.class, options), getJdbcTypeCode()); + st.setObject(name, javaType.unwrap(value, String.class, options), getJdbcTypeCode()); } }; } diff --git a/hibernate-types-60/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java b/hibernate-types-60/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java index 53a04b9e2..8b508053e 100644 --- a/hibernate-types-60/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java +++ b/hibernate-types-60/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java @@ -1,6 +1,5 @@ package com.vladmihalcea.hibernate.type.json; -import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonNode; import com.vladmihalcea.hibernate.util.AbstractPostgreSQLIntegrationTest; import com.vladmihalcea.hibernate.util.ExceptionUtil; @@ -164,8 +163,8 @@ public void testInvalidJson() { }); fail("An invalid JSON should throw an exception!"); } catch (Exception e) { - JsonParseException rootCause = ExceptionUtil.rootCause(e); - assertTrue(rootCause.getMessage().contains("Unexpected character (':'")); + Exception rootCause = ExceptionUtil.rootCause(e); + assertTrue(rootCause.getMessage().contains("invalid input syntax for type json")); } }