Skip to content

Commit a2f92c0

Browse files
committed
Change JsonBinarySqlTypeDescriptor to bind the JSON object as String #423
1 parent e976235 commit a2f92c0

File tree

9 files changed

+16
-27
lines changed

9 files changed

+16
-27
lines changed

hibernate-types-4/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.vladmihalcea.hibernate.type.json.internal;
22

3-
import com.fasterxml.jackson.databind.JsonNode;
43
import org.hibernate.type.descriptor.ValueBinder;
54
import org.hibernate.type.descriptor.WrapperOptions;
65
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
76
import org.hibernate.type.descriptor.sql.BasicBinder;
87

9-
import java.sql.CallableStatement;
108
import java.sql.PreparedStatement;
119
import java.sql.SQLException;
1210

@@ -22,7 +20,7 @@ public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescript
2220
return new BasicBinder<X>(javaTypeDescriptor, this) {
2321
@Override
2422
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
25-
st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
23+
st.setObject(index, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType());
2624
}
2725
};
2826
}

hibernate-types-43/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.vladmihalcea.hibernate.type.json.internal;
22

3-
import com.fasterxml.jackson.databind.JsonNode;
43
import org.hibernate.type.descriptor.ValueBinder;
54
import org.hibernate.type.descriptor.WrapperOptions;
65
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
76
import org.hibernate.type.descriptor.sql.BasicBinder;
87

9-
import java.sql.CallableStatement;
108
import java.sql.PreparedStatement;
119
import java.sql.SQLException;
1210

@@ -22,7 +20,7 @@ public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescript
2220
return new BasicBinder<X>(javaTypeDescriptor, this) {
2321
@Override
2422
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
25-
st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
23+
st.setObject(index, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType());
2624
}
2725
};
2826
}

hibernate-types-5/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.vladmihalcea.hibernate.type.json.internal;
22

3-
import com.fasterxml.jackson.databind.JsonNode;
43
import org.hibernate.type.descriptor.ValueBinder;
54
import org.hibernate.type.descriptor.WrapperOptions;
65
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
@@ -22,13 +21,13 @@ public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescript
2221
return new BasicBinder<X>(javaTypeDescriptor, this) {
2322
@Override
2423
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
25-
st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
24+
st.setObject(index, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType());
2625
}
2726

2827
@Override
2928
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
3029
throws SQLException {
31-
st.setObject(name, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
30+
st.setObject(name, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType());
3231
}
3332
};
3433
}

hibernate-types-52/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.vladmihalcea.hibernate.type.json.internal;
22

3-
import com.fasterxml.jackson.databind.JsonNode;
43
import org.hibernate.type.descriptor.ValueBinder;
54
import org.hibernate.type.descriptor.WrapperOptions;
65
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
@@ -22,13 +21,13 @@ public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescript
2221
return new BasicBinder<X>(javaTypeDescriptor, this) {
2322
@Override
2423
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
25-
st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
24+
st.setObject(index, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType());
2625
}
2726

2827
@Override
2928
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
3029
throws SQLException {
31-
st.setObject(name, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
30+
st.setObject(name, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType());
3231
}
3332
};
3433
}

hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.vladmihalcea.hibernate.type.json;
22

3-
import com.fasterxml.jackson.core.JsonParseException;
43
import com.fasterxml.jackson.databind.JsonNode;
54
import com.vladmihalcea.hibernate.util.AbstractPostgreSQLIntegrationTest;
65
import com.vladmihalcea.hibernate.util.ExceptionUtil;
@@ -152,8 +151,8 @@ public void testInvalidJson() {
152151
});
153152
fail("An invalid JSON should throw an exception!");
154153
} catch (Exception e) {
155-
JsonParseException rootCause = ExceptionUtil.rootCause(e);
156-
assertTrue(rootCause.getMessage().contains("Unexpected character (':'"));
154+
Exception rootCause = ExceptionUtil.rootCause(e);
155+
assertTrue(rootCause.getMessage().contains("invalid input syntax for type json"));
157156
}
158157
}
159158

hibernate-types-55/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinarySqlTypeDescriptor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.vladmihalcea.hibernate.type.json.internal;
22

3-
import com.fasterxml.jackson.databind.JsonNode;
43
import org.hibernate.type.descriptor.ValueBinder;
54
import org.hibernate.type.descriptor.WrapperOptions;
65
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
@@ -22,13 +21,13 @@ public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescript
2221
return new BasicBinder<X>(javaTypeDescriptor, this) {
2322
@Override
2423
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
25-
st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
24+
st.setObject(index, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType());
2625
}
2726

2827
@Override
2928
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
3029
throws SQLException {
31-
st.setObject(name, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
30+
st.setObject(name, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType());
3231
}
3332
};
3433
}

hibernate-types-55/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.vladmihalcea.hibernate.type.json;
22

3-
import com.fasterxml.jackson.core.JsonParseException;
43
import com.fasterxml.jackson.databind.JsonNode;
54
import com.vladmihalcea.hibernate.util.AbstractPostgreSQLIntegrationTest;
65
import com.vladmihalcea.hibernate.util.ExceptionUtil;
@@ -152,8 +151,8 @@ public void testInvalidJson() {
152151
});
153152
fail("An invalid JSON should throw an exception!");
154153
} catch (Exception e) {
155-
JsonParseException rootCause = ExceptionUtil.rootCause(e);
156-
assertTrue(rootCause.getMessage().contains("Unexpected character (':'"));
154+
Exception rootCause = ExceptionUtil.rootCause(e);
155+
assertTrue(rootCause.getMessage().contains("invalid input syntax for type json"));
157156
}
158157
}
159158

hibernate-types-60/src/main/java/com/vladmihalcea/hibernate/type/json/internal/JsonBinaryJdbcTypeDescriptor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.vladmihalcea.hibernate.type.json.internal;
22

3-
import com.fasterxml.jackson.databind.JsonNode;
43
import org.hibernate.type.descriptor.ValueBinder;
54
import org.hibernate.type.descriptor.WrapperOptions;
65
import org.hibernate.type.descriptor.java.JavaType;
@@ -22,13 +21,13 @@ public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
2221
return new BasicBinder<X>(javaType, this) {
2322
@Override
2423
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
25-
st.setObject(index, javaType.unwrap(value, JsonNode.class, options), getJdbcTypeCode());
24+
st.setObject(index, javaType.unwrap(value, String.class, options), getJdbcTypeCode());
2625
}
2726

2827
@Override
2928
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
3029
throws SQLException {
31-
st.setObject(name, javaType.unwrap(value, JsonNode.class, options), getJdbcTypeCode());
30+
st.setObject(name, javaType.unwrap(value, String.class, options), getJdbcTypeCode());
3231
}
3332
};
3433
}

hibernate-types-60/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonStringPropertyTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.vladmihalcea.hibernate.type.json;
22

3-
import com.fasterxml.jackson.core.JsonParseException;
43
import com.fasterxml.jackson.databind.JsonNode;
54
import com.vladmihalcea.hibernate.util.AbstractPostgreSQLIntegrationTest;
65
import com.vladmihalcea.hibernate.util.ExceptionUtil;
@@ -164,8 +163,8 @@ public void testInvalidJson() {
164163
});
165164
fail("An invalid JSON should throw an exception!");
166165
} catch (Exception e) {
167-
JsonParseException rootCause = ExceptionUtil.rootCause(e);
168-
assertTrue(rootCause.getMessage().contains("Unexpected character (':'"));
166+
Exception rootCause = ExceptionUtil.rootCause(e);
167+
assertTrue(rootCause.getMessage().contains("invalid input syntax for type json"));
169168
}
170169
}
171170

0 commit comments

Comments
 (0)