public static byte[] serializeAsBytes(Document document) { return serializeAsBytes(document, true); }
public static byte[] serializeAsBytes(Map object) { return serializeAsBytes(object, true); }
/** * Set the JSON body (the first MIME body) for the writer. * * @param body The DocumentRevision to be serialised as JSON */ public void setBody(Map<String, Object> body) { this.id = (String) body.get(CouchConstants._id); this.bodyBytes = JSONUtils.serializeAsBytes(body); contentLength += bodyBytes.length; }
private byte[] getJsonBytes() { if(bytes == null) { assert map != null; bytes = JSONUtils.serializeAsBytes(map); } return bytes.clone(); }
public void putCheckpoint(String replicatorIdentifier, Object sequence) throws DocumentException { logger.entering("DatastoreWrapper","putCheckpoint",new Object[]{replicatorIdentifier,sequence}); String checkpointDocumentId = getCheckpointDocumentId(replicatorIdentifier); Map<String, Object> checkpointDoc = new HashMap<String, Object>(); checkpointDoc.put("lastSequence", sequence); byte[] json = JSONUtils.serializeAsBytes(checkpointDoc); dbCore.insertLocalDocument(checkpointDocumentId, DocumentBodyFactory.create(json)); }
public String getReplicationId() throws DocumentStoreException { HashMap<String, String> dict = new HashMap<String, String>(); dict.put("source", this.sourceDb.getIdentifier()); dict.put("target", this.targetDb.getIdentifier()); // get raw SHA-1 of dictionary try { byte[] sha1Bytes = Misc.getSha1(new ByteArrayInputStream(JSONUtils.serializeAsBytes(dict))); // return SHA-1 as a hex string byte[] sha1Hex = new Hex().encode(sha1Bytes); return new String(sha1Hex, Charset.forName("UTF-8")); } catch (IOException ioe) { throw new DocumentStoreException(ioe); } }
@Test public void serializeAsBytes() { Map obj = new HashMap<String, String>(); obj.put("name", "the great wall"); String json = "{\"name\":\"the great wall\"}"; Arrays.equals(json.getBytes(), JSONUtils.serializeAsBytes(obj)); }
@Test(expected = IllegalStateException.class) public void serializeAsBytes_invalidMap_exception() { Map obj = new HashMap<String, String>(); obj.put(null, "the great wall"); JSONUtils.serializeAsBytes(obj); }
public String getReplicationId() throws DocumentStoreException { HashMap<String, String> dict = new HashMap<String, String>(); dict.put("source", this.sourceDb.getIdentifier()); dict.put("target", this.targetDb.getIdentifier()); if (filter != null) { dict.put("filter", this.filter.toQueryString()); } else if (selector != null) { dict.put("selector", this.selector); } else if (docIds != null && !docIds.isEmpty()) { dict.put("docIds", Misc.join(",",docIds)); } // get raw SHA-1 of dictionary try { byte[] sha1Bytes = Misc.getSha1(new ByteArrayInputStream(JSONUtils.serializeAsBytes (dict))); // return SHA-1 as a hex string byte[] sha1Hex = new Hex().encode(sha1Bytes); return new String(sha1Hex, Charset.forName("UTF-8")); } catch (IOException ioe) { throw new DocumentStoreException(ioe); } }