Refine search
String[] queryAccountContactUrls(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); HttpURLConnection connection = sendPostAsGetRequest(account, staging, getAccountUrl(account, staging), null, HttpURLConnection.HTTP_OK); JsonObject jsonResponse = getJsonResponse(connection); JsonArray contactsArray = jsonResponse.getJsonArray(CONTACT); if (contactsArray != null && contactsArray.size() > 0) { List<String> contacts = new ArrayList<>(contactsArray.size()); for (JsonString contact : contactsArray.getValuesAs(JsonString.class)) { contacts.add(contact.getString()); } return contacts.toArray(new String[contacts.size()]); } return null; }
if (json.containsKey("name")) { final Object value = json.get("name"); if (value instanceof JsonString) { final String valueString = ((JsonString) value).getString(); displayName = valueString; dependency.setName(valueString); if (json.containsKey("license")) { final Object value = json.get("license"); if (value instanceof JsonString) { final StringBuilder sb = new StringBuilder(); boolean addComma = false; for (int x = 0; x < array.size(); x++) { if (!array.isNull(x)) { if (addComma) { sb.append(", "); addComma = true; if (ValueType.STRING == array.get(x).getValueType()) { sb.append(array.getString(x)); } else {
private void decodeUnknownParam(String name, JsonValue value, Position position) { if (value instanceof JsonNumber) { if (((JsonNumber) value).isIntegral()) { position.set(name, ((JsonNumber) value).longValue()); } else { position.set(name, ((JsonNumber) value).doubleValue()); } position.set(name, ((JsonNumber) value).doubleValue()); } else if (value instanceof JsonString) { position.set(name, ((JsonString) value).getString()); } else if (value == JsonValue.TRUE || value == JsonValue.FALSE) { position.set(name, value == JsonValue.TRUE); } }
private boolean hasValidAudience(JsonObject claims) throws RealmUnavailableException { if (this.audiences.isEmpty()) return true; JsonValue audience = claims.get("aud"); if (audience == null) { log.debug("Token does not contain an audience claim"); return false; } JsonArray audClaimArray; if (JsonValue.ValueType.STRING.equals(audience.getValueType())) { audClaimArray = Json.createArrayBuilder().add(audience).build(); } else { audClaimArray = (JsonArray) audience; } boolean valid = audClaimArray.stream() .map(jsonValue -> (JsonString) jsonValue) .anyMatch(audience1 -> audiences.contains(audience1.getString())); if (!valid) { log.debugf("Audience check failed. Provided [%s] but was expected [%s].", audClaimArray.toArray(), this.audiences); } return valid; }
public IpGroup parseIpGroup(JsonObject obj) { IpGroup retVal = new IpGroup(); if (obj.containsKey("id")) { retVal.setId(Long.valueOf(obj.getInt("id"))); } retVal.setDisplayName(obj.getString("name", null)); retVal.setDescription(obj.getString("description", null)); retVal.setPersistedGroupAlias(obj.getString("alias", null)); if ( obj.containsKey("ranges") ) { obj.getJsonArray("ranges").stream() .filter( jv -> jv.getValueType()==JsonValue.ValueType.ARRAY ) .map( jv -> (JsonArray)jv ) .forEach( rr -> { retVal.add( IpAddressRange.make(IpAddress.valueOf(rr.getString(0)), IpAddress.valueOf(rr.getString(1)))); }); } if ( obj.containsKey("addresses") ) { obj.getJsonArray("addresses").stream() .map( jsVal -> IpAddress.valueOf(((JsonString)jsVal).getString()) ) .map( addr -> IpAddressRange.make(addr, addr) ) .forEach( retVal::add ); } return retVal; }
@Override public Address parseAddress(JsonObject json) { JsonArray results = json.getJsonArray("results"); if (!results.isEmpty()) { Address address = new Address(); JsonObject result = (JsonObject) results.get(0); JsonArray components = result.getJsonArray("address_components"); if (result.containsKey("formatted_address")) { address.setFormattedAddress(result.getString("formatted_address")); for (JsonObject component : components.getValuesAs(JsonObject.class)) { String value = component.getString("short_name"); typesLoop: for (JsonString type : component.getJsonArray("types").getValuesAs(JsonString.class)) { switch (type.getString()) { case "street_number": address.setHouse(value);
public static Object[] fromJsonArray(final JsonArray jsonArray) throws Exception { Object[] array = new Object[jsonArray.size()]; for (int i = 0; i < jsonArray.size(); i++) { Object val = jsonArray.get(i); Set<String> keys = jsonObject.keySet(); Object innerVal = jsonObject.get(key); innerVal = ((JsonString) innerVal).getString(); } else if (innerVal == JsonValue.FALSE) { innerVal = Boolean.FALSE; } else if (innerVal instanceof JsonNumber) { JsonNumber jsonNumber = (JsonNumber) innerVal; if (jsonNumber.isIntegral()) { innerVal = jsonNumber.longValue(); } else { innerVal = jsonNumber.doubleValue(); Set<String> innerKeys = o.keySet(); for (String k : innerKeys) { innerMap.put(k, o.get(k)); array[i] = ((JsonString) val).getString(); } else if (val == JsonValue.FALSE) { array[i] = Boolean.FALSE;
private static String asString(JsonValue value) { if (JsonValue.ValueType.STRING.equals(value.getValueType())) { return ((JsonString) value).getString(); } return value.toString(); } }
HttpURLConnection connection = sendGetRequest(account.getServerUrl(staging), HttpURLConnection.HTTP_OK, JSON_CONTENT_TYPE); JsonObject directoryJson = getJsonResponse(connection); JsonObject metadata = directoryJson.getJsonObject(META); if (metadata == null) { return null; metadataBuilder.setWebsiteUrl(websiteUrl); JsonArray caaIdentitiesArray = metadata.getJsonArray(CAA_IDENTITIES); if (caaIdentitiesArray != null) { final List<String> caaIdentities = new ArrayList<>(caaIdentitiesArray.size()); for (JsonString caaIdentity : caaIdentitiesArray.getValuesAs(JsonString.class)) { caaIdentities.add(caaIdentity.getString()); boolean externalAccountRequired = metadata.getBoolean(EXTERNAL_ACCOUNT_REQUIRED, false); metadataBuilder.setExternalAccountRequired(externalAccountRequired); return metadataBuilder.build();
checkContextForValue(); switch (value.getValueType()) { case ARRAY: JsonArray array = (JsonArray)value; JsonObject object = (JsonObject)value; writeStartObject(); for(Map.Entry<String, JsonValue> member: object.entrySet()) { write(member.getKey(), member.getValue()); case STRING: JsonString str = (JsonString)value; write(str.getString()); break; case NUMBER: JsonNumber number = (JsonNumber)value; writeValue(number.toString()); popFieldContext(); break;
/** * Map a field value to a string, either directly or via the symbolic map. * * @param field the object field to examine * * @return the resulting string, or null if invalid */ @Nullable protected String desymbolize(@Nonnull final JsonValue field) { switch (field.getValueType()) { case STRING: return ((JsonString) field).getString(); case NUMBER: return symbolics.inverse().get(((JsonNumber) field).intValueExact()); default: return null; } }
/** * Gets the value of the specified key from the {@link javax.json.JsonObject} * * @param name the key whose value is to be retrieved. * @param jsonObject the JSON object representing headers or claims set. * @return the value of the specified key. */ public static String getValue(String name, JsonObject jsonObject) { JsonValue value = jsonObject.get(name); if (value != null) { if (ARRAY.equals(value.getValueType())) { JsonArray array = (JsonArray) value; for (JsonValue jsonValue : array) { return getValue(jsonValue); } } else if (STRING.equals(value.getValueType())) { return ((JsonString) value).getString(); } else if (NUMBER.equals(value.getValueType())) { return ((JsonNumber) value).bigDecimalValue().toPlainString(); } else if (TRUE.equals(value.getValueType()) || FALSE.equals(value.getValueType())) { return value.toString(); } } return null; } }
@Override public Double deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize ) { switch( json.getValueType() ) { case NULL: return null; case NUMBER: return ( (JsonNumber) json ).doubleValue(); case STRING: String string = ( (JsonString) json ).getString(); return string.isEmpty() ? 0D : Double.parseDouble( string ); default: throw new SerializationException( "Don't know how to deserialize Double from " + json ); } } }
if (json.containsKey(key)) { final JsonValue value = json.get(key); if (value instanceof JsonString) { evidenceStr = ((JsonString) value).getString(); dep.addEvidence(t, PACKAGE_JSON, key, evidenceStr, 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) { evidenceStr = ((JsonString) subValue).getString(); dep.addEvidence(t, PACKAGE_JSON, String.format("%s.%s", key, property),
@Override public Optional<Function<JsonValue, Stream<ValidationResult.ValidationError>>> create(final ValidationContext model) { if (model.getSchema().getString("type", "object").equals("string")) { return Optional.ofNullable(model.getSchema().get("pattern")) .filter(val -> val.getValueType() == JsonValue.ValueType.STRING) .map(pattern -> new Impl(model.toPointer(), model.getValueProvider(), predicateFactory.apply(JsonString.class.cast(pattern).getString()))); } return Optional.empty(); }
@Override public void serialize(JsonValue value, ObjectWriter writer, Context ctx) { ValueType type = value.getValueType(); if (ValueType.STRING == type) writer.writeValue(((JsonString) value).getString()); else if (ValueType.ARRAY == type) writeArray((JsonArray) value, writer, ctx); else if (ValueType.OBJECT == type) writeObject((JsonObject) value, writer, ctx); else if (ValueType.NULL == type) writer.writeNull(); else if (ValueType.NUMBER == type) { JsonNumber num = (JsonNumber) value; if (num.isIntegral()) writer.writeValue(num.longValue()); else writer.writeValue(num.bigDecimalValue()); } else if (ValueType.FALSE == type) writer.writeValue(false); else if (ValueType.TRUE == type) writer.writeValue(true); else { throw new IllegalStateException("Unknown ValueType " + type); } }
private static String getJsonValueAsString(JsonValue value) { return (value != null && value.getValueType() == ValueType.STRING) ? ((JsonString) value).getString() : null; }
private JsonPointer getPointer(JsonObject operation, String member) { JsonString pointerString = operation.getJsonString(member); if (pointerString == null) { missingMember(operation.getString("op"), member); } return Json.createPointer(pointerString.getString()); }
public TopLevelDocument<String> readTLD(JsonObject object) { String type = null; URI identity = null; List<NamedProperty<String>> properties = new ArrayList<>(); for(Map.Entry<String, JsonValue> me : object.entrySet()) { type = me.getKey(); if(!me.getValue().getValueType().equals(JsonValue.ValueType.OBJECT)) { throw new IllegalArgumentException("Expecting object, got: " + me.getValue()); } for(Map.Entry<String, JsonValue> nme : ((JsonObject) me.getValue()).entrySet()) { if(nme.getKey().equals(rdfAbout)) { identity = URI.create(((JsonString) nme.getValue()).getString()); } else { for(JsonValue jv : (JsonArray) nme.getValue()) { properties.add(Datatree.<String>NamedProperty(nme.getKey(), readPV(jv))); } } } } return Datatree.TopLevelDocument( type, identity, Datatree.NamedProperties(properties)); }
@Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { FullHttpRequest request = (FullHttpRequest) msg; JsonArray result = Json.createReader(new StringReader(request.content().toString(StandardCharsets.UTF_8))) .readArray(); List<Position> positions = new LinkedList<>(); for (int i = 0; i < result.size(); i++) { JsonObject message = result.getJsonObject(i); JsonString ident = message.getJsonString("ident"); if (ident == null) { continue; } DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ident.getString()); if (deviceSession == null) { continue; } Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); decodePosition(message, position); positions.add(position); } sendResponse(channel, HttpResponseStatus.OK); return positions; }