List of usage examples for javax.json JsonObject get
V get(Object key);
From source file:org.jboss.as.test.integration.logging.formatters.JsonFormatterTestCase.java
private static void validateDefault(final JsonObject json, final Collection<String> expectedKeys, final String expectedMessage) { final Set<String> remainingKeys = new HashSet<>(json.keySet()); // Check all the expected keys for (String key : expectedKeys) { checkNonNull(json, key);/* ww w . ja v a 2 s.c om*/ Assert.assertTrue("Missing key " + key + " from JSON object: " + json, remainingKeys.remove(key)); } // Should have no more remaining keys Assert.assertTrue("There are remaining keys that were not validated: " + remainingKeys, remainingKeys.isEmpty()); Assert.assertEquals("org.jboss.logging.Logger", json.getString("loggerClassName")); Assert.assertEquals(LoggingServiceActivator.LOGGER.getName(), json.getString("loggerName")); Assert.assertTrue("Invalid level found in " + json.get("level"), isValidLevel(json.getString("level"))); Assert.assertEquals(expectedMessage, json.getString("message")); }
From source file:org.owasp.dependencycheck.analyzer.NodePackageAnalyzer.java
/** * Adds information to an evidence collection from the node json configuration. * * @param json information from node.js//from ww w . j a v a 2 s . co m * @param collection a set of evidence about a dependency * @param key the key to obtain the data from the json information */ private void addToEvidence(JsonObject json, EvidenceCollection collection, String key) { if (json.containsKey(key)) { final JsonValue value = json.get(key); if (value instanceof JsonString) { collection.addEvidence(PACKAGE_JSON, key, ((JsonString) value).getString(), Confidence.HIGHEST); } else if (value instanceof JsonObject) { final JsonObject jsonObject = (JsonObject) value; for (final Map.Entry<String, JsonValue> entry : jsonObject.entrySet()) { final String property = entry.getKey(); final JsonValue subValue = entry.getValue(); if (subValue instanceof JsonString) { collection.addEvidence(PACKAGE_JSON, String.format("%s.%s", key, property), ((JsonString) subValue).getString(), Confidence.HIGHEST); } else { LOGGER.warn("JSON sub-value not string as expected: {}", subValue); } } } else { LOGGER.warn("JSON value not string or JSON object as expected: {}", value); } } }
From source file:se.curity.oauth.JwtWithCertTest.java
@Test public void testValidContentInToken() throws Exception { JwtValidator validator = new JwtValidatorWithCert(ISSUER, AUDIENCE, prepareKeyMap()); JwtData result = validator.validate(_testToken); _logger.info("test token = {}", _testToken); assertNotNull(result);//ww w .jav a 2s . c o m JsonObject jsonObject = result.getJsonObject(); assertTrue(jsonObject.containsKey("sub")); assertTrue(jsonObject.containsKey(EXTRA_CLAIM)); assertEquals(SUBJECT, ((JsonString) jsonObject.get("sub")).getString()); assertEquals(EXTRA_CLAIM_VALUE, ((JsonString) jsonObject.get(EXTRA_CLAIM)).getString()); }
From source file:org.hyperledger.fabric.sdk.NetworkConfig.java
private static JsonObject getJsonObject(JsonObject object, String propName) { JsonObject obj = null;/*w w w .jav a 2s.co m*/ JsonValue val = object.get(propName); if (val != null && val.getValueType() == ValueType.OBJECT) { obj = val.asJsonObject(); } return obj; }
From source file:tools.xor.logic.DefaultJson.java
protected void checkStringField() throws JSONException { // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); Settings settings = new Settings(); settings.setEntityClass(Person.class); Person person = (Person) aggregateService.create(jsonBuilder.build(), settings); assert (person.getId() != null); assert (person.getName().equals("DILIP_DALTON")); Object jsonObject = aggregateService.read(person, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); }
From source file:tools.xor.logic.DefaultJson.java
protected void checkIntField() throws JSONException { // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); jsonBuilder.add("employeeNo", 235); Settings settings = new Settings(); settings.setEntityClass(Employee.class); Employee employee = (Employee) aggregateService.create(jsonBuilder.build(), settings); assert (employee.getId() != null); assert (employee.getName().equals("DILIP_DALTON")); assert (employee.getEmployeeNo() == 235); Object jsonObject = aggregateService.read(employee, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); assert (((JsonNumber) json.get("employeeNo")).intValue() == 235); }
From source file:tools.xor.logic.DefaultJson.java
protected void checkLongField() throws JSONException { // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); jsonBuilder.add("salary", 100000); Settings settings = new Settings(); settings.setEntityClass(Employee.class); Employee employee = (Employee) aggregateService.create(jsonBuilder.build(), settings); assert (employee.getId() != null); assert (employee.getName().equals("DILIP_DALTON")); assert (employee.getSalary() == 100000); Object jsonObject = aggregateService.read(employee, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); assert (((JsonNumber) json.get("salary")).intValue() == 100000); }
From source file:tools.xor.logic.DefaultJson.java
protected void checkEmptyLongField() throws JSONException { // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); Settings settings = new Settings(); settings.setEntityClass(Employee.class); Employee employee = (Employee) aggregateService.create(jsonBuilder.build(), settings); assert (employee.getId() != null); assert (employee.getName().equals("DILIP_DALTON")); assert (employee.getSalary() == null); assert (!employee.getIsCriticalSystemObject()); Object jsonObject = aggregateService.read(employee, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); assert (!json.containsKey("salary")); }
From source file:tools.xor.logic.DefaultJson.java
protected void checkBooleanField() throws JSONException { // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); jsonBuilder.add("isCriticalSystemObject", true); Settings settings = new Settings(); settings.setEntityClass(Employee.class); Employee employee = (Employee) aggregateService.create(jsonBuilder.build(), settings); assert (employee.getId() != null); assert (employee.getName().equals("DILIP_DALTON")); assert (employee.getIsCriticalSystemObject()); Object jsonObject = aggregateService.read(employee, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); assert (json.getBoolean("isCriticalSystemObject")); }
From source file:tools.xor.logic.DefaultJson.java
protected void checkBigDecimalField() throws JSONException { final BigDecimal largeDecimal = new BigDecimal("12345678998765432100000.123456789987654321"); // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); jsonBuilder.add("largeDecimal", largeDecimal); Settings settings = new Settings(); settings.setEntityClass(Employee.class); Employee employee = (Employee) aggregateService.create(jsonBuilder.build(), settings); assert (employee.getId() != null); assert (employee.getName().equals("DILIP_DALTON")); assert (employee.getLargeDecimal().equals(largeDecimal)); Object jsonObject = aggregateService.read(employee, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); assert (((JsonNumber) json.get("largeDecimal")).bigDecimalValue().equals(largeDecimal)); }