@Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { try { String value = rs.getString(names[0]); if (value == null) { return null; } Object object = null; if (isArray) { ObjectMapper objectMapper = ObjectMapperBeanFactory.getObjectMapper(); JavaType type = objectMapper.getTypeFactory().constructCollectionType(List.class, targetClass); object = objectMapper.readValue(value, type); } else { ObjectMapper objectMapper = ObjectMapperBeanFactory.getObjectMapper(); object = objectMapper.readValue(value, targetClass); } return object; } catch (IOException e) { throw new HibernateException(e); } }
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { try { if (value == null) { st.setNull(index, Types.CLOB); return; } ObjectMapper objectMapper = ObjectMapperBeanFactory.getObjectMapper(); String stringValue = objectMapper.writeValueAsString(value); st.setString(index, stringValue); } catch (JsonProcessingException e) { throw new HibernateException(e); } }