dto: < /strong> < /p>
Код: Выделить всё
@XmlElement
private Object value;
Код: Выделить всё
@Column(name = "value")
@Convert(converter = JpaConverterJson.class)
private Object value;
Код: Выделить всё
@Component
@Converter
@Slf4j
public class JpaConverterJson implements AttributeConverter {
@Autowired
private ObjectMapper objectMapper;
@Override
public String convertToDatabaseColumn(Object meta) {
try {
objectMapper.disable(SerializationFeature.WRAP_ROOT_VALUE);
return objectMapper.writeValueAsString(meta);
} catch (JsonProcessingException ex) {
log.error("JsonProcessingException encoding Object into String: {}", ex.getMessage());
return null;
}
}
@Override
public Object convertToEntityAttribute(String dbData) {
try {
return objectMapper.readValue(dbData, Object.class);
} catch (IOException ex) {
log.error("IOException decoding json from database: {}", ex.getMessage());
return null;
}
}
}
Когда я запускаю нативный запрос SQL вставки, данные хранятся правильно.
Код: Выделить всё
com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Data too long for column 'value' at row 1
Подробнее здесь: https://stackoverflow.com/questions/796 ... for-column
Мобильная версия