Search in sources :

Example 1 with JsonAttributeValue

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));
    }
}
Also used : JsonAttributeValue(io.jans.orm.sql.model.JsonAttributeValue) QueryException(com.querydsl.core.QueryException) DeleteException(io.jans.orm.exception.operation.DeleteException) MappingException(io.jans.orm.exception.MappingException) PersistenceException(io.jans.orm.exception.operation.PersistenceException) EntryConvertationException(io.jans.orm.exception.operation.EntryConvertationException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) SQLException(java.sql.SQLException) SearchException(io.jans.orm.exception.operation.SearchException) EntryNotFoundException(io.jans.orm.exception.operation.EntryNotFoundException) MappingException(io.jans.orm.exception.MappingException)

Example 2 with JsonAttributeValue

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));
    }
}
Also used : JsonAttributeValue(io.jans.orm.sql.model.JsonAttributeValue) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) QueryException(com.querydsl.core.QueryException) DeleteException(io.jans.orm.exception.operation.DeleteException) MappingException(io.jans.orm.exception.MappingException) PersistenceException(io.jans.orm.exception.operation.PersistenceException) EntryConvertationException(io.jans.orm.exception.operation.EntryConvertationException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) SQLException(java.sql.SQLException) SearchException(io.jans.orm.exception.operation.SearchException) EntryNotFoundException(io.jans.orm.exception.operation.EntryNotFoundException) MappingException(io.jans.orm.exception.MappingException)

Aggregations

QueryException (com.querydsl.core.QueryException)2 MappingException (io.jans.orm.exception.MappingException)2 DeleteException (io.jans.orm.exception.operation.DeleteException)2 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)2 EntryConvertationException (io.jans.orm.exception.operation.EntryConvertationException)2 EntryNotFoundException (io.jans.orm.exception.operation.EntryNotFoundException)2 PersistenceException (io.jans.orm.exception.operation.PersistenceException)2 SearchException (io.jans.orm.exception.operation.SearchException)2 JsonAttributeValue (io.jans.orm.sql.model.JsonAttributeValue)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1