List of usage examples for com.fasterxml.jackson.databind JsonNode equals
public abstract boolean equals(Object paramObject);
From source file:com.almende.eve.state.redis.RedisState.java
@Override public boolean locPutIfUnchanged(final String key, final JsonNode newVal, JsonNode oldVal) { boolean result = false; final Jedis redis = provider.getInstance(); try {// w w w. j av a 2 s. c om JsonNode cur = get(key); if (oldVal == null) { oldVal = NullNode.getInstance(); } final String nkey = makeKey(key); if (oldVal.equals(cur) || oldVal.toString().equals(cur.toString())) { redis.set(nkey, newVal.toString()); redis.sadd(getId() + "_" + KEYS, nkey); result = true; } } catch (Exception e) { LOG.log(Level.WARNING, "", e); // Don't let users loop if exception is thrown. They // would get into a deadlock.... result = true; } provider.returnInstance(redis); return result; }
From source file:com.auditbucket.engine.service.WhatService.java
/** * Locate and compare the two JSON What documents to determine if they have changed * * * @param metaHeader thing being tracked * @param compareFrom existing change to compare from * @param compareWith new Change to compare with - JSON format * @return false if different, true if same *///from w w w .j a va 2 s . c o m public boolean isSame(MetaHeader metaHeader, ChangeLog compareFrom, String compareWith) { if (compareFrom == null) return false; LogWhat what = getWhat(metaHeader, compareFrom); if (what == null) return false; String jsonThis = what.getWhat(); if (jsonThis == null || compareWith == null) return false; if (jsonThis.length() != compareWith.length()) return false; // Compare values JsonNode compareTo = null; JsonNode other = null; try { compareTo = om.readTree(jsonThis); other = om.readTree(compareWith); } catch (IOException e) { logger.error("Comparing JSON docs"); } return !(compareTo == null || other == null) && compareTo.equals(other); }
From source file:com.flipkart.zjsonpatch.JsonDiffTest.java
@Test public void testSampleJsonDiff() throws Exception { for (int i = 0; i < jsonNode.size(); i++) { JsonNode first = jsonNode.get(i).get("first"); JsonNode second = jsonNode.get(i).get("second"); System.out.println("Test # " + i); System.out.println(first); System.out.println(second); JsonNode actualPatch = JsonDiff.asJson(first, second); System.out.println(actualPatch); JsonNode secondPrime = JsonPatch.apply(actualPatch, first); System.out.println(secondPrime); Assert.assertTrue(second.equals(secondPrime)); }/*from w ww. j a va 2 s . c o m*/ }
From source file:org.camunda.spin.impl.json.jackson.JacksonJsonNode.java
public Integer indexOf(Object searchObject) { ensureNotNull("searchObject", searchObject); if (this.isArray()) { Integer i = 0;//from w w w. ja v a 2s.c o m JsonNode node = dataFormat.createJsonNode(searchObject); for (Iterator<JsonNode> nodeIterator = jsonNode.elements(); nodeIterator.hasNext(); i++) { JsonNode n = nodeIterator.next(); if (n.equals(node)) { return i; } } // when searchObject is not found throw LOG.unableToFindProperty(node.asText()); } else { throw LOG.unableToGetIndex(jsonNode.getNodeType().name()); } }
From source file:org.camunda.spin.impl.json.jackson.JacksonJsonNode.java
public Integer lastIndexOf(Object searchObject) { ensureNotNull("searchObject", searchObject); if (this.isArray()) { Integer i = 0;/* w w w . ja v a 2s . c o m*/ Integer j = -1; JsonNode node = dataFormat.createJsonNode(searchObject); for (Iterator<JsonNode> nodeIterator = jsonNode.elements(); nodeIterator.hasNext(); i++) { JsonNode n = nodeIterator.next(); if (n.equals(node)) { j = i; } } // when searchObject is not found if (j == -1) { throw LOG.unableToFindProperty(node.getNodeType().name()); } return j; } else { throw LOG.unableToGetIndex(jsonNode.getNodeType().name()); } }
From source file:com.flipkart.zjsonpatch.JsonDiffTest.java
@Test public void testGeneratedJsonDiff() throws Exception { Random random = new Random(); for (int i = 0; i < 1000; i++) { JsonNode first = TestDataGenerator.generate(random.nextInt(10)); JsonNode second = TestDataGenerator.generate(random.nextInt(10)); JsonNode actualPatch = JsonDiff.asJson(first, second); System.out.println("Test # " + i); System.out.println(first); System.out.println(second); System.out.println(actualPatch); JsonNode secondPrime = JsonPatch.apply(actualPatch, first); System.out.println(secondPrime); Assert.assertTrue(second.equals(secondPrime)); }/* w w w . j av a 2 s . com*/ }
From source file:org.opendaylight.sfc.sbrest.json.SfgExporterTest.java
private boolean testExportSfgJson(String expectedResultFile, boolean nameOnly) throws IOException { ServiceFunctionGroup serviceFunctionGroup; String exportedSfgString;//from w ww . j a va 2 s. c o m SfgExporterFactory sfgExporterFactory = new SfgExporterFactory(); if (nameOnly) { serviceFunctionGroup = this.buildServiceFunctionGroupNameOnly(); exportedSfgString = sfgExporterFactory.getExporter().exportJsonNameOnly(serviceFunctionGroup); } else { serviceFunctionGroup = this.buildServiceFunctionGroup(); exportedSfgString = sfgExporterFactory.getExporter().exportJson(serviceFunctionGroup); } ObjectMapper objectMapper = new ObjectMapper(); JsonNode expectedSfgJson = objectMapper .readTree(this.gatherServiceFunctionGroupJsonStringFromFile(expectedResultFile)); JsonNode exportedSfgJson = objectMapper.readTree(exportedSfgString); System.out.println("EXPECTED: " + expectedSfgJson); System.out.println("EXPORTED: " + exportedSfgJson); return expectedSfgJson.equals(exportedSfgJson); }
From source file:com.redhat.lightblue.eval.SetExpressionEvaluator.java
private boolean oldAndNewAreDifferent(JsonNode oldValueNode, JsonNode newValueNode) { if (oldValueNode == null && newValueNode != null) { return true; } else if (oldValueNode != null && newValueNode == null) { return true; } else if (oldValueNode != null && newValueNode != null) { return !oldValueNode.equals(newValueNode); } else {/*from ww w .ja v a2s . co m*/ return false; } }
From source file:org.opendaylight.sfc.sbrest.json.SffExporterTest.java
private boolean testExportSffJson(String expectedResultFile, boolean nameOnly) throws IOException { ServiceFunctionForwarder serviceFunctionForwarder; String exportedSffString;/*from w w w .j a v a2s .com*/ SffExporterFactory sffExporterFactory = new SffExporterFactory(); if (nameOnly) { serviceFunctionForwarder = this.buildServiceFunctionForwarderNameOnly(); exportedSffString = sffExporterFactory.getExporter().exportJsonNameOnly(serviceFunctionForwarder); } else { serviceFunctionForwarder = this.buildServiceFunctionForwarder(); exportedSffString = sffExporterFactory.getExporter().exportJson(serviceFunctionForwarder); } ObjectMapper objectMapper = new ObjectMapper(); JsonNode expectedSffJson = objectMapper .readTree(this.gatherServiceFunctionForwardersJsonStringFromFile(expectedResultFile)); JsonNode exportedSffJson = objectMapper.readTree(exportedSffString); System.out.println("EXPECTED: " + expectedSffJson); System.out.println("CREATED: " + exportedSffJson); return expectedSffJson.equals(exportedSffJson); }
From source file:de.thingweb.desc.ThingDescriptionParserTest.java
@Test public void testRoundtrip2() throws Exception { // e.g, JSON Object, see http://w3c.github.io/wot/current-practices/wot-practices.html#td-context // {/*from ww w. j a v a 2 s. co m*/ // "@context": { // "name": "http://www.w3c.org/wot/td#name", // "uris": "http://www.w3c.org/wot/td#associatedUri", // "unit": "http://purl.oclc.org/NET/ssnx/qu/qu-rec20#unit", // "Thing": "http://www.w3c.org/wot/td#Thing", // ... // } // } String tdSample = "{\r\n" + " \"@context\": {\r\n" + " \"name\": \"http://www.w3c.org/wot/td#name\",\r\n" + " \"uris\": \"http://www.w3c.org/wot/td#associatedUri\",\r\n" + " \"unit\": \"http://purl.oclc.org/NET/ssnx/qu/qu-rec20#unit\",\r\n" + " \"Thing\": \"http://www.w3c.org/wot/td#Thing\"\r\n" + " },\r\n" + " \"name\": \"Test\",\r\n" + " \"properties\": [],\r\n" + " \"actions\": [],\r\n" + " \"events\": []\r\n" + "}"; // Thing t = new Thing("myName"); // ObjectNode on = factory.objectNode(); // on.put("name", factory.textNode("http://www.w3c.org/wot/td#name")); // on.put("uris", factory.textNode("http://www.w3c.org/wot/td#associatedUri")); // on.put("unit", factory.textNode("http://purl.oclc.org/NET/ssnx/qu/qu-rec20#unit")); // on.put("Thing", factory.textNode("http://www.w3c.org/wot/td#Thing")); // t.getMetadata().add("@context", on); ObjectMapper mapper = new ObjectMapper(); JsonNode original = mapper.readValue(tdSample, JsonNode.class); JsonNode generated = mapper.readValue( ThingDescriptionParser.toBytes(ThingDescriptionParser.fromBytes(tdSample.getBytes())), JsonNode.class); assertTrue(original.equals(generated)); }