Refine search
public static AddressSettingsInfo from(final String jsonString) { JsonObject object = JsonUtil.readJsonObject(jsonString); return new AddressSettingsInfo(object.getString("addressFullMessagePolicy"), object.getJsonNumber("maxSizeBytes").longValue(), object.getInt("pageSizeBytes"), object.getInt("pageCacheMaxSize"), object.getInt("maxDeliveryAttempts"), object.getJsonNumber("redeliveryDelay").longValue(), object.getJsonNumber("redeliveryMultiplier").doubleValue(), object.getJsonNumber("maxRedeliveryDelay").longValue(), object.getString("DLA"), object.getString("expiryAddress"), object.getBoolean("lastValueQueue"), object.getJsonNumber("redistributionDelay").longValue(), object.getBoolean("sendToDLAOnNoRoute"), object.getJsonNumber("slowConsumerThreshold").longValue(), object.getJsonNumber("slowConsumerCheckPeriod").longValue(), object.getString("slowConsumerPolicy"), object.getBoolean("autoCreateJmsQueues"), object.getBoolean("autoCreateJmsTopics"), object.getBoolean("autoDeleteJmsQueues"), object.getBoolean("autoDeleteJmsTopics")); }
return number.longValue(); } else if (desiredType == Integer.class || desiredType == Integer.TYPE) { return number.intValue(); } else if (desiredType == Double.class || desiredType == Double.TYPE) { return number.doubleValue(); } else { return number.longValue(); return ((JsonString) jsonValue).getString(); } else if (jsonValue instanceof JsonValue) { if (jsonValue == JsonValue.TRUE) {
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(); } else if (val instanceof JsonNumber) { JsonNumber jsonNumber = (JsonNumber) val; if (jsonNumber.isIntegral()) { array[i] = jsonNumber.longValue(); } else { array[i] = jsonNumber.doubleValue();
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); } }
@Override public Optional<Function<JsonValue, Stream<ValidationResult.ValidationError>>> create(final ValidationContext model) { if (model.getSchema().getString("type", "object").equals("number")) { return Optional.ofNullable(model.getSchema().get("exclusiveMinimum")) .filter(v -> v.getValueType() == JsonValue.ValueType.NUMBER) .map(m -> new Impl(model.toPointer(), model.getValueProvider(), JsonNumber.class.cast(m).doubleValue())); } return Optional.empty(); }
private void writeJsonValue(final String name, final JsonValue value) { checkObject(false); switch (value.getValueType()) { case ARRAY: writeStartArray(name); final JsonArray array = JsonArray.class.cast(value); final Iterator<JsonValue> ait = array.iterator(); while (ait.hasNext()) { write(ait.next()); writeStartObject(name); final JsonObject object = JsonObject.class.cast(value); final Iterator<Map.Entry<String, JsonValue>> oit = object.entrySet().iterator(); while (oit.hasNext()) { final Map.Entry<String, JsonValue> keyval = oit.next(); write(name, JsonString.class.cast(value).getString()); break; case NUMBER: if (number.isIntegral()) { write(name, number.longValueExact()); } else { write(name, number.bigDecimalValue());
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, root.getString("IMEI")); if (deviceSession == null) { sendResponse(channel, HttpResponseStatus.BAD_REQUEST); JsonArray records = root.getJsonArray("Records"); for (int i = 0; i < records.size(); i++) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); JsonObject record = records.getJsonObject(i); position.set(Position.KEY_INDEX, record.getInt("SeqNo")); position.set(Position.KEY_EVENT, record.getInt("Reason")); JsonArray fields = record.getJsonArray("Fields"); for (int j = 0; j < fields.size(); j++) { JsonObject field = fields.getJsonObject(j); switch (field.getInt("FType")) { case 0: position.setFixTime(dateFormat.parse(field.getString("GpsUTC"))); position.setLatitude(field.getJsonNumber("Lat").doubleValue()); position.setLongitude(field.getJsonNumber("Long").doubleValue()); position.setAltitude(field.getInt("Alt")); position.setSpeed(UnitsConverter.knotsFromCps(field.getInt("Spd")));
/** * Create a new Float32MultiArray based on the given JSON object. Any * missing values will be set to their defaults. * * @param jsonObject * The JSON object to parse. * @return A Float32MultiArray message based on the given JSON object. */ public static Float32MultiArray fromJsonObject(JsonObject jsonObject) { // check the layout MultiArrayLayout layout = jsonObject .containsKey(Float32MultiArray.FIELD_LAYOUT) ? MultiArrayLayout .fromJsonObject(jsonObject .getJsonObject(Float32MultiArray.FIELD_LAYOUT)) : new MultiArrayLayout(); // check the array float[] data = new float[] {}; JsonArray jsonData = jsonObject .getJsonArray(Float32MultiArray.FIELD_DATA); if (jsonData != null) { // convert each data data = new float[jsonData.size()]; for (int i = 0; i < data.length; i++) { data[i] = (float) jsonData.getJsonNumber(i).doubleValue(); } } return new Float32MultiArray(layout, data); } }
String schedulesUrl = conferenceBaseUrl + "/schedules/"; LOGGER.debug("Sending a request to: {}", schedulesUrl); JsonArray daysArray = readJson(schedulesUrl, JsonReader::readObject).getJsonArray("links"); for (int i = 0; i < daysArray.size(); i++) { JsonObject dayObject = daysArray.getJsonObject(i); String dayUrl = dayObject.getString("href"); JsonArray daySlotsArray = readJson(dayUrl, JsonReader::readObject).getJsonArray("slots"); for (int j = 0; j < daySlotsArray.size(); j++) { JsonObject timeslotObject = daySlotsArray.getJsonObject(j); LocalDateTime startDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timeslotObject.getJsonNumber("fromTimeMillis").longValue()), ZoneId.of(ZONE_ID)); LocalDateTime endDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timeslotObject.getJsonNumber("toTimeMillis").longValue()), ZoneId.of(ZONE_ID));
/** * Create a new Int64MultiArray based on the given JSON object. Any missing * values will be set to their defaults. * * @param jsonObject * The JSON object to parse. * @return A Int64MultiArray message based on the given JSON object. */ public static Int64MultiArray fromJsonObject(JsonObject jsonObject) { // check the layout MultiArrayLayout layout = jsonObject .containsKey(Int64MultiArray.FIELD_LAYOUT) ? MultiArrayLayout .fromJsonObject(jsonObject .getJsonObject(Int64MultiArray.FIELD_LAYOUT)) : new MultiArrayLayout(); // check the array long[] data = new long[] {}; JsonArray jsonData = jsonObject .getJsonArray(Int64MultiArray.FIELD_DATA); if (jsonData != null) { // convert each data data = new long[jsonData.size()]; for (int i = 0; i < data.length; i++) { data[i] = jsonData.getJsonNumber(i).longValue(); } } return new Int64MultiArray(layout, data); } }
@Override public void completed(JsonObject json) { if (json.containsKey("error")) { callback.onFailure(new GeolocationException(json.getJsonObject("error").getString("message"))); } else { JsonObject location = json.getJsonObject("location"); callback.onSuccess( location.getJsonNumber("lat").doubleValue(), location.getJsonNumber("lng").doubleValue(), json.getJsonNumber("accuracy").doubleValue()); } }
@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("maxLength")) .filter(v -> v.getValueType() == JsonValue.ValueType.NUMBER) .map(m -> new Impl(model.toPointer(), model.getValueProvider(), JsonNumber.class.cast(m).intValue())); } return Optional.empty(); }
@Override public Float deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize ) { switch( json.getValueType() ) { case NULL: return null; case NUMBER: return (float) ( (JsonNumber) json ).doubleValue(); case STRING: String string = ( (JsonString) json ).getString(); return string.isEmpty() ? 0F : Float.parseFloat( string ); default: throw new SerializationException( "Don't know how to deserialize Float from " + json ); } } }
/** * Create a new MultiArrayLayout based on the given JSON object. Any missing * values will be set to their defaults. * * @param jsonObject * The JSON object to parse. * @return A MultiArrayLayout message based on the given JSON object. */ public static MultiArrayLayout fromJsonObject(JsonObject jsonObject) { // check the array MultiArrayDimension[] dim = new MultiArrayDimension[] {}; JsonArray jsonDim = jsonObject.getJsonArray(MultiArrayLayout.FIELD_DIM); if (jsonDim != null) { // convert each property dim = new MultiArrayDimension[jsonDim.size()]; for (int i = 0; i < dim.length; i++) { dim[i] = MultiArrayDimension.fromJsonObject(jsonDim .getJsonObject(i)); } } // check the offset int dataOffset = jsonObject .containsKey(MultiArrayLayout.FIELD_DATA_OFFSET) ? Primitive .toUInt32(jsonObject.getJsonNumber( MultiArrayLayout.FIELD_DATA_OFFSET).longValue()) : 0; return new MultiArrayLayout(dim, dataOffset); } }
@Override public Optional<Function<JsonValue, Stream<ValidationResult.ValidationError>>> create(final ValidationContext model) { return Optional.ofNullable(model.getSchema().get("maxItems")) .filter(it -> it.getValueType() == JsonValue.ValueType.NUMBER) .map(it -> JsonNumber.class.cast(it).intValue()) .filter(it -> it >= 0) .map(max -> new Impl(model.toPointer(), model.getValueProvider(), max)); }
@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); } }
/** {@inheritDoc} */ @Override @Nonnull public SPSession deserialize(final long version, @Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value, @Nullable final Long expiration) throws IOException { if (expiration == null) { throw new IOException("SPSession objects must have an expiration"); } try { final JsonReader reader = Json.createReader(new StringReader(value)); final JsonStructure st = reader.read(); if (!(st instanceof JsonObject)) { throw new IOException("Found invalid data structure while parsing SPSession"); } final JsonObject obj = (JsonObject) st; final String serviceId = obj.getString(SERVICE_ID_FIELD); final long creation = obj.getJsonNumber(CREATION_INSTANT_FIELD).longValueExact(); return doDeserialize(obj, serviceId, creation, expiration - expirationOffset); } catch (final NullPointerException | ClassCastException | ArithmeticException | JsonException e) { log.error("Exception while parsing SPSession", e); throw new IOException("Found invalid data structure while parsing SPSession", e); } }
Assert.assertNotNull(jsonString); JsonArray array = JsonUtil.readJsonArray(jsonString); Assert.assertEquals(2, array.size()); JsonObject first = lookupSession(array, session1); JsonObject second = lookupSession(array, session2); Assert.assertTrue(first.getString("sessionID").length() > 0); Assert.assertEquals(((ClientSessionImpl) session1).getName(), first.getString("sessionID")); Assert.assertTrue(first.getString("principal").length() > 0); Assert.assertEquals("guest", first.getString("principal")); Assert.assertTrue(first.getJsonNumber("creationTime").longValue() > 0); Assert.assertEquals(0, first.getJsonNumber("consumerCount").longValue()); Assert.assertTrue(second.getString("sessionID").length() > 0); Assert.assertTrue(second.getString("principal").length() > 0); Assert.assertEquals("myUser", second.getString("principal")); Assert.assertTrue(second.getJsonNumber("creationTime").longValue() > 0); Assert.assertEquals(1, second.getJsonNumber("consumerCount").longValue());
@Override public void completed(JsonObject json) { if (json.getString("status").equals("error")) { callback.onFailure(new GeolocationException(json.getString("message"))); } else { callback.onSuccess( json.getJsonNumber("lat").doubleValue(), json.getJsonNumber("lon").doubleValue(), json.getJsonNumber("accuracy").doubleValue()); } }
request.content().toString(StandardCharsets.UTF_8).split("=")[0], "UTF-8"))).readObject(); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, json.getString("device")); if (deviceSession == null) { sendResponse(channel, HttpResponseStatus.BAD_REQUEST); position.setDeviceId(deviceSession.getDeviceId()); position.setTime(new Date(json.getInt("time") * 1000L)); ByteBuf buf = Unpooled.wrappedBuffer(DataConverter.parseHex(json.getString("data"))); try { int type = buf.readUnsignedByte() >> 4; position.set(Position.KEY_RSSI, json.getJsonNumber("rssi").doubleValue()); position.set(Position.KEY_INDEX, json.getInt("seqNumber"));