/** * Method for Deserializing any Json message into a Map. * Should the Json message not be a map, it will be wrapped in a map, corresponding to * the JSON: <code>{ "" : <original_json> }</code> */ @SuppressWarnings("unchecked") public static Map<String, Object> fromJson(String json) throws JsonException { try { Object o = toObject(json); if(o instanceof Map) { return (Map<String, Object>) o; } else { HashMap<String, Object> x = new HashMap<String, Object>(); x.put("", o); return x; } } catch(JsonParseException e) { throw new JsonException(e); } }
public String getMessage() { Throwable t = getCause(); while(t.getCause()!=null) { t = t.getCause(); } return t.getMessage(); } }
protected static void printJsonException(HttpResponse response, JsonException e) { logger.error("Received bad JSON"); response.setStatusCode(HttpStatus.SC_BAD_REQUEST); setStringEntity(response, "Unable to parse query: " + e.getMessage()); }
@Override public DatabaseQuery<MemoryType> convert(Query query) { MemoryQuery mq = new MemoryQuery(); try { mq.fromJson(query.toJson()); } catch (JsonException e) { e.printStackTrace(); } return mq; }
@Override public DatabaseDocument<MemoryType> convert(Document<?> document) { MemoryDocument md = new MemoryDocument(); try { md.fromJson(document.toJson()); } catch (JsonException e) { e.printStackTrace(); } return md; }
@SuppressWarnings({ "unchecked" }) @Override public void fromJson(String json) throws JsonException{ try { Map<String, Object> queryObject = (Map<String, Object>) SerializationUtils.fromJson(json); if(queryObject.containsKey("equals")) { equals = (Map<String, Object>) queryObject.get("equals"); } if(queryObject.containsKey("notEquals")) { notEquals = (Map<String, Object>) queryObject.get("notEquals"); } if(queryObject.containsKey("exists")) { exists = (Map<String, Boolean>) queryObject.get("exists"); } if(queryObject.containsKey("touched")) { touched = (Map<String, Boolean>) queryObject.get("touched"); } if(queryObject.containsKey("action")) { action = Action.valueOf((String)queryObject.get("action")); } } catch(JsonParseException jse) { throw new JsonException(jse); } }
@SuppressWarnings("unchecked") @Override public final void fromJson(String json) throws JsonException { try { Map<String, Object> m = SerializationUtils.fromJson(json); if(m.containsKey(ID_KEY)) { documentMap.put(ID_KEY, m.get(ID_KEY)); } if(m.containsKey(ACTION_KEY) && m.get(ACTION_KEY)!=null) { documentMap.put(ACTION_KEY, Action.valueOf((String)m.get(ACTION_KEY))); } if(m.containsKey(METADATA_KEY)) { Map<String, Object> metadata = (Map<String, Object>) m.get(METADATA_KEY); for(Map.Entry<String, Object> e : metadata.entrySet()) { putMetadataField(e.getKey(), metadata.get(e.getKey())); } } if(m.containsKey(CONTENTS_KEY)) { Map<String, Object> content = (Map<String, Object>) m.get(CONTENTS_KEY); for(Map.Entry<String, Object> e : content.entrySet()) { putContentField(e.getKey(), content.get(e.getKey())); } } } catch(JsonParseException e) { internalLogger.error("Caught JsonParseException, throwing JsonException"); throw new JsonException(e); } }
throw new JsonException(jse);