@Test public void testFieldNames() { jsonObject.put("foo", "bar"); jsonObject.put("eek", 123); jsonObject.put("flib", new JsonObject()); Set<String> fieldNames = jsonObject.fieldNames(); assertEquals(3, fieldNames.size()); assertTrue(fieldNames.contains("foo")); assertTrue(fieldNames.contains("eek")); assertTrue(fieldNames.contains("flib")); jsonObject.remove("foo"); assertEquals(2, fieldNames.size()); assertFalse(fieldNames.contains("foo")); }
private static boolean structureMatches(JsonObject match, Object bodyObject) { if (match == null || bodyObject == null) return true; // Can send message other than JSON too - in which case we can't do deep matching on structure of message if (bodyObject instanceof JsonObject) { JsonObject body = (JsonObject) bodyObject; for (String fieldName : match.fieldNames()) { Object mv = match.getValue(fieldName); Object bv = body.getValue(fieldName); // Support deep matching if (mv instanceof JsonObject) { if (!structureMatches((JsonObject) mv, bv)) { return false; } } else if (!match.getValue(fieldName).equals(body.getValue(fieldName))) { return false; } } return true; } return false; }
@Test public void testFieldNames() { jsonObject.put("foo", "bar"); jsonObject.put("eek", 123); jsonObject.put("flib", new JsonObject()); Set<String> fieldNames = jsonObject.fieldNames(); assertEquals(3, fieldNames.size()); assertTrue(fieldNames.contains("foo")); assertTrue(fieldNames.contains("eek")); assertTrue(fieldNames.contains("flib")); jsonObject.remove("foo"); assertEquals(2, fieldNames.size()); assertFalse(fieldNames.contains("foo")); }
private DeliveryOptions parseMsgHeaders(DeliveryOptions options, JsonObject headers) { if (headers == null) return options; Iterator<String> fnameIter = headers.fieldNames().iterator(); String fname; while (fnameIter.hasNext()) { fname = fnameIter.next(); options.addHeader(fname, headers.getString(fname)); } return options; }
private Set<Property> objectToPropSet(JsonObject props) { Set<Property> propSet = new HashSet<Property>(); for (String key : props.fieldNames()) { // TODO: we may need to make this function recursive. propSet.add(new Property(key, props.getMap().get(key))); } return propSet; }
static JsonObject deNull( final JsonObject entity, final boolean immutable) { final JsonObject result = immutable ? entity.copy() : entity; final Set<String> keys = entity.fieldNames() .stream() .filter(field -> Objects.isNull(entity.getValue(field))) .collect(Collectors.toSet()); Observable.fromIterable(keys) .subscribe(result::remove).dispose(); return result; }
static JsonObject deNull( final JsonObject entity, final boolean immutable) { final JsonObject result = immutable ? entity.copy() : entity; final Set<String> keys = entity.fieldNames() .stream() .filter(field -> Objects.isNull(entity.getValue(field))) .collect(Collectors.toSet()); Observable.fromIterable(keys) .subscribe(result::remove).dispose(); return result; }
@Override public Single<Set<String>> listIndices() { return client.readIndex(installationPrefix() + "*").async().map(json -> { return json.fieldNames().stream() // Filter again to ensure we only deal with correct names .filter(i -> i.startsWith(installationPrefix())) // Remove the prefix .map(i -> i.substring(installationPrefix().length())) .collect(Collectors.toSet()); }); }
private Inquiry.Mode parseMode(final JsonObject data) { Inquiry.Mode mode = Inquiry.Mode.LINEAR; for (final String field : data.fieldNames()) { if (Ut.isJObject(data.getValue(field))) { mode = Inquiry.Mode.TREE; break; } } return mode; }
static <T> void execZero(final JsonObject data, final ZeroBiConsumer<T, String> fnIt) throws ZeroException { for (final String name : data.fieldNames()) { final Object item = data.getValue(name); if (null != item) { fnIt.accept((T) item, name); } } }
static <T> void execZero(final JsonObject data, final ZeroBiConsumer<T, String> fnIt) throws ZeroException { for (final String name : data.fieldNames()) { final Object item = data.getValue(name); if (null != item) { fnIt.accept((T) item, name); } } }
private void setTranslateStatus(Rule ruleObj, JsonObject rule) { JsonObject translateStatus = rule.getJsonObject("translateStatus"); if (translateStatus != null) { ruleObj.addTranslateStatus(new LinkedHashMap<>()); for (String pattern : translateStatus.fieldNames()) { ruleObj.getTranslateStatus().put(Pattern.compile(pattern), translateStatus.getInteger(pattern)); } } }
static void appendJson(final JsonObject target, final JsonObject source) { Observable.fromIterable(source.fieldNames()) .filter(key -> !target.containsKey(key)) .subscribe(key -> target.put(key, source.getValue(key))); }
static void appendJson(final JsonObject target, final JsonObject source) { Observable.fromIterable(source.fieldNames()) .filter(key -> !target.containsKey(key)) .subscribe(key -> target.put(key, source.getValue(key))); }
static JsonObject append( final JsonObject target, final JsonObject source, final boolean immutable ) { final JsonObject result = immutable ? target.copy() : target; Observable.fromIterable(source.fieldNames()) .filter(key -> !target.containsKey(key)) .subscribe(key -> result.put(key, source.getValue(key))).dispose(); return result; }
static JsonObject append( final JsonObject target, final JsonObject source, final boolean immutable ) { final JsonObject result = immutable ? target.copy() : target; Observable.fromIterable(source.fieldNames()) .filter(key -> !target.containsKey(key)) .subscribe(key -> result.put(key, source.getValue(key))).dispose(); return result; }
@EnvironmentVariable(name = MESH_AUTH_OAUTH2_SERVER_CONF_CREDENTIALS, description = "Override the configured OAuth2 server credentials (as JSON Object String).") public void setCredentialsViaEnv(JsonObject credentialsObject) { for(String key : credentialsObject.fieldNames()) { Object val = credentialsObject.getValue(key); if (val == null || val instanceof String) { this.addCredential(key, (String) val); } } }
static JsonObject defaultValue( final JsonObject json, final JsonObject filled, final boolean immutable ) { final JsonObject result = immutable ? json.copy() : json; for (final String field : filled.fieldNames()) { defaultValue(result, field, filled.getValue(field), false); } return result; }
private QLinear(final JsonObject data) { this.raw.mergeIn(data.copy()); for (final String field : data.fieldNames()) { // Add this.add(field, data.getValue(field)); } }
private QLinear(final JsonObject data) { this.raw.mergeIn(data.copy()); for (final String field : data.fieldNames()) { // Add this.add(field, data.getValue(field)); } }