|
@@ -14,14 +14,10 @@ import java.sql.SQLException;
|
|
|
|
|
|
|
|
@MappedJdbcTypes(JdbcType.OTHER)
|
|
@MappedJdbcTypes(JdbcType.OTHER)
|
|
|
@MappedTypes(Object.class)
|
|
@MappedTypes(Object.class)
|
|
|
-public class JsonbTypeHandler<T> extends BaseTypeHandler<Object> {
|
|
|
|
|
|
|
+public class JsonbTypeHandler extends BaseTypeHandler<Object> {
|
|
|
|
|
|
|
|
private static final ObjectMapper mapper = new ObjectMapper();
|
|
private static final ObjectMapper mapper = new ObjectMapper();
|
|
|
- private final Class<T> type;
|
|
|
|
|
|
|
|
|
|
- public JsonbTypeHandler(Class<T> type) {
|
|
|
|
|
- this.type = type;
|
|
|
|
|
- }
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException {
|
|
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException {
|
|
|
try {
|
|
try {
|
|
@@ -35,26 +31,26 @@ public class JsonbTypeHandler<T> extends BaseTypeHandler<Object> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public T getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
|
|
|
|
|
|
+ public Object getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
|
|
return parseJson(rs.getString(columnName));
|
|
return parseJson(rs.getString(columnName));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public T getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
|
|
|
|
|
|
+ public Object getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
|
|
return parseJson(rs.getString(columnIndex));
|
|
return parseJson(rs.getString(columnIndex));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public T getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
|
|
|
|
|
|
+ public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
|
|
return parseJson(cs.getString(columnIndex));
|
|
return parseJson(cs.getString(columnIndex));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private T parseJson(String json) throws SQLException {
|
|
|
|
|
|
|
+ private Object parseJson(String json) throws SQLException {
|
|
|
if (json == null) {
|
|
if (json == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- return mapper.readValue(json, type);
|
|
|
|
|
|
|
+ return mapper.readValue(json, Object.class);
|
|
|
} catch (JsonProcessingException e) {
|
|
} catch (JsonProcessingException e) {
|
|
|
throw new SQLException("Error parsing JSONB string", e);
|
|
throw new SQLException("Error parsing JSONB string", e);
|
|
|
}
|
|
}
|