/** Logger component. */
public static transient Logger logger = Logger.getLogger(QueryJSONDeserializer.class);
public Query deserializeQuery(Object o, IDataSource dataSource) throws SerializationException {
Query query;
JSONObject queryJSON = null;
JSONArray fieldsJSON = null;
JSONArray filtersJSON = null;
JSONArray havingsJSON = null;
JSONObject expressionJSON = null;
JSONArray subqueriesJSON = null;
Query subquery;
logger.debug("IN");
try {
Assert.assertNotNull(o, "Object to be deserialized cannot be null");
if(o instanceof String) {
logger.debug("Deserializing string [" + (String)o + "]");
try {
queryJSON = new JSONObject( (String)o );
} catch(Throwable t) {
logger.debug("Object to be deserialized must be string encoding a JSON object");
throw new SerializationException("An error occurred while deserializing query: " + (String)o, t);
}
} else if(o instanceof JSONObject) {
queryJSON = (JSONObject)o;
} else {
Assert.assertUnreachable("Object to be deserialized must be of type string or of type JSONObject, not of type [" + o.getClass().getName() + "]");
}
query = new Query();
try {
query.setId(queryJSON.getString(QuerySerializationConstants.ID));
query.setName(queryJSON.optString(QuerySerializationConstants.NAME));
query.setDescription(queryJSON.optString(QuerySerializationConstants.DESCRIPTION));