List of usage examples for com.fasterxml.jackson.databind JsonNode toString
public abstract String toString();
From source file:com.github.tomakehurst.wiremock.matching.StringValuePatternJsonDeserializer.java
private EqualToJsonPattern deserializeEqualToJson(JsonNode rootNode) throws JsonMappingException { if (!rootNode.has("equalToJson")) { throw new JsonMappingException(rootNode.toString() + " is not a valid comparison"); }/*from ww w . j a v a 2 s . com*/ String operand = rootNode.findValue("equalToJson").textValue(); boolean ignoreArrayOrder = fromNullable(rootNode.findValue("ignoreArrayOrder")); boolean ignoreExtraElements = fromNullable(rootNode.findValue("ignoreExtraElements")); return new EqualToJsonPattern(operand, ignoreArrayOrder, ignoreExtraElements); }
From source file:com.redhat.lightblue.crud.ldap.ITCaseLdapCRUDController_DataType_Test.java
@Test public void testInsertThenFindField() throws Exception { String insert = loadResource("./crud/insert/datatype-insert-template.json").replaceFirst("#cn", cn) .replaceFirst("#field", fieldName).replaceFirst("#fielddata", data); Response insertResponse = lightblueFactory.getMediator() .insert(createRequest_FromJsonString(InsertionRequest.class, insert)); assertNotNull(insertResponse);//from w w w .j a v a 2 s. c om assertNoErrors(insertResponse); assertNoDataErrors(insertResponse); assertEquals(1, insertResponse.getModifiedCount()); String find = loadResource("./crud/find/datatype-find-template.json").replaceFirst("#cn", cn) .replaceFirst("#field", fieldName); Response findResponse = lightblueFactory.getMediator() .find(createRequest_FromJsonString(FindRequest.class, find)); assertNotNull(findResponse); assertNoErrors(findResponse); assertNoDataErrors(findResponse); assertEquals(1, findResponse.getMatchCount()); JsonNode entityData = findResponse.getEntityData(); assertNotNull(entityData); JSONAssert.assertEquals("[{\"" + fieldName + "\":\"" + data + "\"}]", entityData.toString(), true); }
From source file:com.redhat.lightblue.metadata.types.BooleanType.java
@Override public Object fromJson(JsonNode node) { if (node.isValueNode()) { return node.asBoolean(); } else {/*from w w w . j a v a 2 s . c om*/ throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, node.toString()); } }
From source file:com.infinities.keystone4j.admin.v3.credential.CredentialResourceTest.java
@Test public void testUpdateCredentail() throws ClientProtocolException, IOException { String blobStr = JsonUtils.toJsonWithoutPrettyPrint(blob); Credential c = new Credential(); c.setType("s3"); CredentialWrapper wrapper = new CredentialWrapper(c); System.err.println(JsonUtils.toJson(wrapper)); PatchClient client = new PatchClient("http://localhost:9998/v3/credentials/" + credential.getId()); JsonNode node = client.connect(wrapper); System.err.println(node.toString()); JsonNode credentialJ = node.get("credential"); assertEquals(credential.getId(), credentialJ.get("id").asText()); assertEquals("s3", credentialJ.get("type").asText()); assertEquals(credential.getProjectId(), credentialJ.get("project_id").asText()); assertEquals(credential.getUserId(), credentialJ.get("user_id").asText()); assertEquals(blobStr, credentialJ.get("blob").asText()); }
From source file:com.redhat.lightblue.metadata.types.IntegerType.java
@Override public Object fromJson(JsonNode node) { if (node.isValueNode()) { return node.asLong(); } else {/* www .j a v a2s .c o m*/ throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, node.toString()); } }
From source file:com.github.tomakehurst.wiremock.matching.StringValuePatternJsonDeserializer.java
private MatchesXPathPattern deserialiseMatchesXPathPattern(JsonNode rootNode) throws JsonMappingException { if (!rootNode.has("matchesXPath")) { throw new JsonMappingException(rootNode.toString() + " is not a valid comparison"); }/*from w w w .j a va 2 s. co m*/ String operand = rootNode.findValue("matchesXPath").textValue(); JsonNode namespacesNode = rootNode.findValue("xPathNamespaces"); Map<String, String> namespaces = namespacesNode != null ? toNamespaceMap(namespacesNode) : Collections.<String, String>emptyMap(); return new MatchesXPathPattern(operand, namespaces); }
From source file:com.infinities.keystone4j.admin.v3.policy.PolicyV3ResourceTest.java
@Test public void testListPolicies() throws JsonProcessingException, IOException { Response response = target("/v3/policies").register(JacksonFeature.class) .register(ObjectMapperResolver.class).request() .header("X-Auth-Token", Config.Instance.getOpt(Config.Type.DEFAULT, "admin_token").asText()).get(); assertEquals(200, response.getStatus()); JsonNode node = JsonUtils.convertToJsonNode(response.readEntity(String.class)); System.err.println(node.toString()); JsonNode policiesJ = node.get("policies"); assertEquals(1, policiesJ.size());/*from w w w. j a v a 2 s. c om*/ JsonNode policyJ = policiesJ.get(0); assertNotNull(policyJ.get("id").asText()); assertNotNull(policyJ.get("blob").asText()); assertNotNull(policyJ.get("type").asText()); assertNotNull(policyJ.get("user_id").asText()); assertNotNull(policyJ.get("project_id").asText()); assertNotNull(policyJ.get("links")); assertNotNull(policyJ.get("links").get("self").asText()); }
From source file:com.infinities.keystone4j.admin.v3.policy.PolicyV3ResourceTest.java
@Test public void testGetPolicy() throws JsonGenerationException, JsonMappingException, IOException { Response response = target("/v3/policies").path(policy.getId()).register(JacksonFeature.class) .register(ObjectMapperResolver.class).request() .header("X-Auth-Token", Config.Instance.getOpt(Config.Type.DEFAULT, "admin_token").asText()).get(); assertEquals(200, response.getStatus()); JsonNode node = JsonUtils.convertToJsonNode(response.readEntity(String.class)); System.err.println(node.toString()); JsonNode policyJ = node.get("policy"); assertEquals(policy.getId(), policyJ.get("id").asText()); assertEquals(policy.getType(), policyJ.get("type").asText()); assertEquals(policy.getUserId(), policyJ.get("user_id").asText()); assertEquals(policy.getProjectId(), policyJ.get("project_id").asText()); assertTrue(policyJ.get("blob").hasNonNull("default")); assertEquals(policy.getBlob().get("default"), policyJ.get("blob").get("default").asBoolean()); assertNotNull(policyJ.get("links")); assertNotNull(policyJ.get("links").get("self").asText()); }
From source file:com.redhat.lightblue.metadata.types.DoubleType.java
@Override public Object fromJson(JsonNode node) { if (node.isValueNode()) { return node.asDouble(); } else {/*www . ja v a 2s . com*/ throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, node.toString()); } }
From source file:com.salmon.security.xacml.demo.springmvc.rest.controller.MarketPlacePopulatorController.java
@ExceptionHandler(HttpMessageNotReadableException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)/* w w w . j a va 2s.co m*/ public void whenPayloadIsStrange(HttpServletRequest request, HttpMessageNotReadableException ex) { StringBuilder sb = new StringBuilder("REQUEST PARTS: "); LOG.info("************************ JSON ERROR ************************ "); LOG.info("ContentType " + request.getContentType()); LOG.info("ContentLength " + request.getContentLength()); StringBuffer jb = new StringBuffer(); String line = null; try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) jb.append(line); } catch (Exception e) { /*report an error*/ } LOG.info("************************ JSON PARSING ************************ "); LOG.info("Payload: " + jb.toString()); try { ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser jp = factory.createParser(jb.toString()); JsonNode actualObj = mapper.readTree(jp); LOG.info("JSON OBJECT CREATED: " + actualObj.toString()); ObjectMapper driverMapper = new ObjectMapper(); Driver jsonDriver = driverMapper.readValue(actualObj.toString(), Driver.class); LOG.info("DRIVER OBJECT CREATED: " + jsonDriver.toString()); } catch (Exception e) { LOG.error("JSON Parsing Exception " + e.getMessage()); } }