@Test public void testDeleteResultMetadata() throws Exception { Result result = new ResultImpl(true); result.setResultStatus(new ResultStatus(ResultStatus.STATUS.OK)); DeleteResultMetadata metadata = new DeleteResultMetadata(); metadata.addDeletedKey("key1"); metadata.addException("key2", new AuthorizationException()); result.setResultMetadata(metadata); String expected = "{\n" + " \"deleteResult\" : [\n"+ " {\n" + " \"deleted\" : {\n" + " \"key\" : \"key1\"\n" + " }\n" + " },\n" + " {\n" + " \"error\" : {\n" + " \"key\" : \"key2\",\n" + " \"code\" : 403,\n" + " \"message\" : \"org.apache.ambari.server.security.authorization.AuthorizationException:"+ " The authenticated user is not authorized to perform the requested operation\"\n" + " }\n" + " }\n" + " ]\n" + "}"; String json = new JsonSerializer().serialize(result).toString().replace("\r", ""); assertEquals(expected, json); }
@Override public Object serialize(Result result) { try { ByteArrayOutputStream bytesOut = init(); if (result.getStatus().isErrorState()) { return serializeError(result.getStatus()); } TreeNode<Resource> treeNode = result.getResultTree(); processNode(treeNode); processResultMetadata(result.getResultMetadata()); m_generator.close(); return bytesOut.toString("UTF-8"); } catch (IOException e) { throw new RuntimeException("Unable to serialize to json: " + e, e); } }
JsonSerializer implements ResultSerializer { @Override public Object serialize(Result result) { try { ByteArrayOutputStream bytesOut = init(); if (result.getStatus().isErrorState()) { return serializeError(result.getStatus()); } TreeNode<Resource> treeNode = result.getResultTree(); processNode(treeNode); processResultMetadata(result.getResultMetadata()); m_generator.close(); return bytesOut.toString("UTF-8"); } catch (IOException e) { throw new RuntimeException("Unable to serialize to json: " + e, e); } } }
JsonSerializer implements ResultSerializer { @Override public Object serialize(Result result) { try { ByteArrayOutputStream bytesOut = init(); if (result.getStatus().isErrorState()) { return serializeError(result.getStatus()); } TreeNode<Resource> treeNode = result.getResultTree(); processNode(treeNode); processResultMetadata(result.getResultMetadata()); m_generator.close(); return bytesOut.toString("UTF-8"); } catch (IOException e) { throw new RuntimeException("Unable to serialize to json: " + e, e); } }  }
JsonSerializer implements ResultSerializer { @Override public Object serialize(Result result) { try { ByteArrayOutputStream bytesOut = init(); if (result.getStatus().isErrorState()) { return serializeError(result.getStatus()); } TreeNode<Resource> treeNode = result.getResultTree(); processNode(treeNode); processResultMetadata(result.getResultMetadata()); m_generator.close(); return bytesOut.toString("UTF-8"); } catch (IOException e) { throw new RuntimeException("Unable to serialize to json: " + e, e); } }  @Override Object serialize(Result result); @Override Object serializeError(ResultStatus error); }
JsonSerializer implements ResultSerializer { @Override public Object serialize(Result result) { try { ByteArrayOutputStream bytesOut = init(); if (result.getStatus().isErrorState()) { return serializeError(result.getStatus()); } TreeNode<Resource> treeNode = result.getResultTree(); processNode(treeNode); processResultMetadata(result.getResultMetadata()); m_generator.close(); return bytesOut.toString("UTF-8"); } catch (IOException e) { throw new RuntimeException("Unable to serialize to json: " + e, e); } }  @Override Object serialize(Result result); @Override Object serializeError(ResultStatus error);  }