@Test public void testSerializeRegular() throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final RowSerializer rowSerializer = new JsonRowSerializer(StandardCharsets.UTF_8); rowSerializer.serialize(rowKey, cells, out); final String json = out.toString(StandardCharsets.UTF_8.name()); Assert.assertEquals("{\"row\":\"row1\", \"cells\": {\"colFam1:colQual1\":\"val1\", \"colFam2:colQual2\":\"val2\"}}", json); }
@Override public String serialize(byte[] rowKey, ResultCell[] cells) { final StringBuilder jsonBuilder = new StringBuilder(); jsonBuilder.append("{"); final String row = new String(rowKey, charset); jsonBuilder.append("\"row\":") .append("\"") .append(StringEscapeUtils.escapeJson(row)) .append("\""); jsonBuilder.append(", \"cells\": {"); int i = 0; for (final ResultCell cell : cells) { final String cellFamily = new String(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength(), charset); final String cellQualifier = new String(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength(), charset); if (i > 0) { jsonBuilder.append(", "); } jsonBuilder.append("\"") .append(StringEscapeUtils.escapeJson(cellFamily)) .append(":") .append(StringEscapeUtils.escapeJson(cellQualifier)) .append("\":\"") .append(StringEscapeUtils.escapeJson(new String(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength(), charset))) .append("\""); i++; } jsonBuilder.append("}}"); return jsonBuilder.toString(); }
JsonRowSerializer implements RowSerializer { @Override public String serialize(byte[] rowKey, ResultCell[] cells) { final StringBuilder jsonBuilder = new StringBuilder(); jsonBuilder.append("{"); final String row = new String(rowKey, charset); jsonBuilder.append("\"row\":") .append("\"") .append(StringEscapeUtils.escapeJson(row)) .append("\""); jsonBuilder.append(", \"cells\": {"); int i = 0; for (final ResultCell cell : cells) { final String cellFamily = new String(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength(), charset); final String cellQualifier = new String(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength(), charset); if (i > 0) { jsonBuilder.append(", "); } jsonBuilder.append("\"") .append(StringEscapeUtils.escapeJson(cellFamily)) .append(":") .append(StringEscapeUtils.escapeJson(cellQualifier)) .append("\":\"") .append(StringEscapeUtils.escapeJson(new String(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength(), charset))) .append("\""); i++; } jsonBuilder.append("}}"); return jsonBuilder.toString(); } }
JsonRowSerializer implements RowSerializer { @Override public String serialize(byte[] rowKey, ResultCell[] cells) { final StringBuilder jsonBuilder = new StringBuilder(); jsonBuilder.append("{"); final String row = new String(rowKey, charset); jsonBuilder.append("\"row\":") .append("\"") .append(StringEscapeUtils.escapeJson(row)) .append("\""); jsonBuilder.append(", \"cells\": {"); int i = 0; for (final ResultCell cell : cells) { final String cellFamily = new String(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength(), charset); final String cellQualifier = new String(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength(), charset); if (i > 0) { jsonBuilder.append(", "); } jsonBuilder.append("\"") .append(StringEscapeUtils.escapeJson(cellFamily)) .append(":") .append(StringEscapeUtils.escapeJson(cellQualifier)) .append("\":\"") .append(StringEscapeUtils.escapeJson(new String(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength(), charset))) .append("\""); i++; } jsonBuilder.append("}}"); return jsonBuilder.toString(); } JsonRowSerializer(final Charset charset); }
JsonRowSerializer implements RowSerializer { @Override public String serialize(byte[] rowKey, ResultCell[] cells) { final StringBuilder jsonBuilder = new StringBuilder(); jsonBuilder.append("{"); final String row = new String(rowKey, charset); jsonBuilder.append("\"row\":") .append("\"") .append(StringEscapeUtils.escapeJson(row)) .append("\""); jsonBuilder.append(", \"cells\": {"); int i = 0; for (final ResultCell cell : cells) { final String cellFamily = new String(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength(), charset); final String cellQualifier = new String(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength(), charset); if (i > 0) { jsonBuilder.append(", "); } jsonBuilder.append("\"") .append(StringEscapeUtils.escapeJson(cellFamily)) .append(":") .append(StringEscapeUtils.escapeJson(cellQualifier)) .append("\":\"") .append(StringEscapeUtils.escapeJson(new String(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength(), charset))) .append("\""); i++; } jsonBuilder.append("}}"); return jsonBuilder.toString(); } JsonRowSerializer(final Charset charset); @Override String serialize(byte[] rowKey, ResultCell[] cells); @Override void serialize(final byte[] rowKey, final ResultCell[] cells, final OutputStream out); }
JsonRowSerializer implements RowSerializer { @Override public String serialize(byte[] rowKey, ResultCell[] cells) { final StringBuilder jsonBuilder = new StringBuilder(); jsonBuilder.append("{"); final String row = new String(rowKey, charset); jsonBuilder.append("\"row\":") .append("\"") .append(StringEscapeUtils.escapeJson(row)) .append("\""); jsonBuilder.append(", \"cells\": {"); int i = 0; for (final ResultCell cell : cells) { final String cellFamily = new String(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength(), charset); final String cellQualifier = new String(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength(), charset); if (i > 0) { jsonBuilder.append(", "); } jsonBuilder.append("\"") .append(StringEscapeUtils.escapeJson(cellFamily)) .append(":") .append(StringEscapeUtils.escapeJson(cellQualifier)) .append("\":\"") .append(StringEscapeUtils.escapeJson(new String(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength(), charset))) .append("\""); i++; } jsonBuilder.append("}}"); return jsonBuilder.toString(); } JsonRowSerializer(final Charset charset); @Override String serialize(byte[] rowKey, ResultCell[] cells); @Override void serialize(final byte[] rowKey, final ResultCell[] cells, final OutputStream out);  }