/** * Functionally the same as calling SerializationUtils.toObject(<pre>json</pre>).getClass() */ public static Class<?> getResultingClass(String json) { try { return toObject(json).getClass(); } catch (JsonException e) { return null; } }
@Override public DocumentID<MongoType> toDocumentIdFromJson(String json) { try { return toDocumentId(SerializationUtils.toObject(json)); } catch (JsonException e) { logger.error("Error deserializing json", e); return null; } }
public static LocalDocumentID getDocumentID(String json) throws JsonException { return new LocalDocumentID(SerializationUtils.toObject(json)); }
@SuppressWarnings("unchecked") public static List<String> getStages(String host, int port, String group) throws IOException { HttpConnection connection = new HttpConnection(host, port); HttpResponse response = connection.get("/"+GET_STAGES_URL+"?"+GROUP_PARAM+"="+group); if(response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { logger.error("Unable to get list stages in the group"); return new ArrayList<String>(); } try { return (List<String>) SerializationUtils.toObject(EntityUtils.toString(response.getEntity())); } catch (JsonException e) { logger.error("Unable to deserialize list of stages", e); return new ArrayList<String>(); } } }
/** * 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); } }
@SuppressWarnings("unchecked") public List<String> getFileNames(DocumentID<?> docid) { try { HttpResponse response = core.get(fileUrl + "&" + HttpEndpointConstants.DOCID_PARAM + "=" + URLEncoder.encode(docid.toJSON(), "UTF-8")); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { try { return (List<String>) SerializationUtils.toObject(EntityUtils.toString(response.getEntity())); } catch (JsonException e) { throw new IOException(e); } } else { logUnexpected("getFileNames()", response); return null; } } catch (IOException e) { throw new RuntimeException(e); } }
@SuppressWarnings("rawtypes") @Override public DocumentID<MongoType> toDocumentId(Object jsonPrimitive) { if (jsonPrimitive instanceof Map) { return new MongoDocumentID(new ObjectId((Integer) ((Map) jsonPrimitive).get("_time"), (Integer) ((Map) jsonPrimitive).get("_machine"), (Integer) ((Map) jsonPrimitive).get("_inc"))); } else if(jsonPrimitive instanceof String) { try { Object o = SerializationUtils.toObject((String) jsonPrimitive); if (o instanceof Map) { return toDocumentId(o); } } catch (JsonException e) { //Do nothing } } logger.error("Serialized ID was not deserialized to map. The type was a "+jsonPrimitive.getClass()+". Was it created by a Hydra database of this type?"); return null; }
Object o; try { o = SerializationUtils.toObject(EntityUtils.toString(response.getEntity())); } catch (JsonException e) { throw new IOException(e);