use of io.jans.orm.sql.model.JsonAttributeValue in project jans by JanssenProject.
the class SqlOperationServiceImpl method convertDbJsonToValue.
private Object[] convertDbJsonToValue(String jsonValue) {
try {
// Object[] values = JSON_OBJECT_MAPPER.readValue(jsonValue, Object[].class);
JsonAttributeValue attributeValue = JSON_OBJECT_MAPPER.readValue(jsonValue, JsonAttributeValue.class);
Object[] values = null;
if (attributeValue != null) {
values = attributeValue.getValues();
}
return values;
} catch (Exception ex) {
LOG.error("Failed to convert json value '{}' to array:", jsonValue, ex);
throw new MappingException(String.format("Failed to convert json value '%s' to array", jsonValue));
}
}
use of io.jans.orm.sql.model.JsonAttributeValue in project jans by JanssenProject.
the class SqlOperationServiceImpl method convertValueToDbJson.
private String convertValueToDbJson(Object propertyValue) {
try {
// String value = JSON_OBJECT_MAPPER.writeValueAsString(propertyValue);
JsonAttributeValue attributeValue;
if (propertyValue == null) {
attributeValue = new JsonAttributeValue();
}
if (propertyValue instanceof List) {
attributeValue = new JsonAttributeValue(((List) propertyValue).toArray());
} else if (propertyValue.getClass().isArray()) {
attributeValue = new JsonAttributeValue((Object[]) propertyValue);
} else {
attributeValue = new JsonAttributeValue(new Object[] { propertyValue });
}
String value = JSON_OBJECT_MAPPER.writeValueAsString(attributeValue);
return value;
} catch (Exception ex) {
LOG.error("Failed to convert '{}' to json value:", propertyValue, ex);
throw new MappingException(String.format("Failed to convert '%s' to json value", propertyValue));
}
}
Aggregations