com.eclipsesource.json.JsonValue Java Examples
The following examples show how to use
com.eclipsesource.json.JsonValue.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FullClient.java From Skype4J with Apache License 2.0 | 6 votes |
@Override public void getContactRequests(boolean fromWebsocket) throws ConnectionException { JsonArray array = Endpoints.AUTH_REQUESTS_URL .open(this) .as(JsonArray.class) .expect(200, "While loading authorization requests") .get(); for (JsonValue contactRequest : array) { JsonObject contactRequestObj = contactRequest.asObject(); try { ContactRequestImpl request = new ContactRequestImpl(contactRequestObj.get("event_time").asString(), contactRequestObj.get("sender").asString(), contactRequestObj.get("greeting").asString(), this); if (this.allContactRequests.add(request)) { if (fromWebsocket) { ContactRequestEvent event = new ContactRequestEvent(request); getEventDispatcher().callEvent(event); } } } catch (java.text.ParseException e) { getLogger().log(Level.WARNING, "Could not parse date for contact request", e); } } if (fromWebsocket) this.updateContactList(); }
Example #2
Source File: Util.java From r2cloud with Apache License 2.0 | 6 votes |
private static JsonValue convertPrimitive(Object value) { JsonValue jsonValue; if (value instanceof Integer) { jsonValue = Json.value((Integer) value); } else if (value instanceof Long) { jsonValue = Json.value((Long) value); } else if (value instanceof Float) { jsonValue = Json.value((Float) value); } else if (value instanceof Double) { jsonValue = Json.value((Double) value); } else if (value instanceof Boolean) { jsonValue = Json.value((Boolean) value); } else if (value instanceof Byte) { jsonValue = Json.value((Byte) value); } else if (value instanceof Short) { jsonValue = Json.value((Short) value); } else if (value instanceof String) { jsonValue = Json.value((String) value); } else { jsonValue = null; } return jsonValue; }
Example #3
Source File: Settings.java From java-disassembler with GNU General Public License v3.0 | 6 votes |
public static void loadGUI() { try { JsonObject settings = JsonObject.readFrom(new FileReader(JDA.settingsFile)); for (JDADecompiler decompiler : Decompilers.getAllDecompilers()) decompiler.getSettings().loadFrom(settings); for (Setting setting : Settings.ALL_SETTINGS) { String nodeId = setting.node; JsonValue nodeValue = settings.get(nodeId); if (nodeValue != null) { if ((nodeValue = nodeValue.asObject().get(setting.name)) != null) setting.set(nodeValue.asString()); } } } catch (Exception e) { e.printStackTrace(); } }
Example #4
Source File: FullClient.java From Skype4J with Apache License 2.0 | 6 votes |
@Override public void updateContactList() throws ConnectionException { JsonObject obj = Endpoints.GET_ALL_CONTACTS .open(this, getUsername(), "notification") .as(JsonObject.class) .expect(200, "While loading contacts") .get(); for (JsonValue value : obj.get("contacts").asArray()) { if (value.asObject().get("suggested") == null || !value.asObject().get("suggested").asBoolean()) { String id = value.asObject().get("id").asString(); ContactImpl impl = (ContactImpl) allContacts.get(id); if (impl == null) impl = (ContactImpl) loadContact(id); impl.update(value.asObject()); } } }
Example #5
Source File: ProbeVenvInfoAction.java From pygradle with Apache License 2.0 | 6 votes |
private static void getSavedTags(PythonDetails pythonDetails, EditablePythonAbiContainer editablePythonAbiContainer, File supportedAbiFormatsFile) throws IOException { JsonArray array = Json.parse(new FileReader(supportedAbiFormatsFile)).asArray(); for (JsonValue jsonValue : array) { JsonObject entry = jsonValue.asObject(); String pythonTag = entry.get("pythonTag").asString(); String abiTag = entry.get("abiTag").asString(); String platformTag = entry.get("platformTag").asString(); AbiDetails triple = new AbiDetails(pythonDetails.getVirtualEnvInterpreter(), pythonTag, abiTag, platformTag); editablePythonAbiContainer.addSupportedAbi(triple); } }
Example #6
Source File: BoxTermsOfService.java From box-java-sdk with Apache License 2.0 | 6 votes |
/** * Retrieves a list of Terms of Service that belong to your Enterprise as an Iterable. * @param api api the API connection to be used by the resource. * @param termsOfServiceType the type of terms of service to be retrieved. Can be set to "managed" or "external" * @return the Iterable of Terms of Service in an Enterprise that match the filter parameters. */ public static List<BoxTermsOfService.Info> getAllTermsOfServices(final BoxAPIConnection api, BoxTermsOfService.TermsOfServiceType termsOfServiceType) { QueryStringBuilder builder = new QueryStringBuilder(); if (termsOfServiceType != null) { builder.appendParam("tos_type", termsOfServiceType.toString()); } URL url = ALL_TERMS_OF_SERVICES_URL_TEMPLATE.buildWithQuery(api.getBaseURL(), builder.toString()); BoxAPIRequest request = new BoxAPIRequest(api, url, "GET"); BoxJSONResponse response = (BoxJSONResponse) request.send(); JsonObject responseJSON = JsonObject.readFrom(response.getJSON()); int totalCount = responseJSON.get("total_count").asInt(); List<BoxTermsOfService.Info> termsOfServices = new ArrayList<BoxTermsOfService.Info>(totalCount); JsonArray entries = responseJSON.get("entries").asArray(); for (JsonValue value : entries) { JsonObject termsOfServiceJSON = value.asObject(); BoxTermsOfService termsOfService = new BoxTermsOfService(api, termsOfServiceJSON.get("id").asString()); BoxTermsOfService.Info info = termsOfService.new Info(termsOfServiceJSON); termsOfServices.add(info); } return termsOfServices; }
Example #7
Source File: NetworkConfigWebResourceTest.java From onos with Apache License 2.0 | 6 votes |
/** * Tests the result of the rest api GET when there is a config. */ @Test public void testConfigs() { setUpConfigData(); final WebTarget wt = target(); final String response = wt.path("network/configuration").request().get(String.class); final JsonObject result = Json.parse(response).asObject(); Assert.assertThat(result, notNullValue()); Assert.assertThat(result.names(), hasSize(2)); JsonValue devices = result.get("devices"); Assert.assertThat(devices, notNullValue()); JsonValue device1 = devices.asObject().get("device1"); Assert.assertThat(device1, notNullValue()); JsonValue basic = device1.asObject().get("basic"); Assert.assertThat(basic, notNullValue()); checkBasicAttributes(basic); }
Example #8
Source File: R2ServerClient.java From r2cloud with Apache License 2.0 | 6 votes |
private static Long readObservationId(String con) { JsonValue result; try { result = Json.parse(con); } catch (ParseException e) { LOG.info("malformed json"); return null; } if (!result.isObject()) { LOG.info("malformed json"); return null; } JsonObject resultObj = result.asObject(); String status = resultObj.getString("status", null); if (status == null || !status.equalsIgnoreCase("SUCCESS")) { LOG.info("response error: {}", resultObj); return null; } long id = resultObj.getLong("id", -1); if (id == -1) { return null; } return id; }
Example #9
Source File: ZCashClientCaller.java From zencash-swing-wallet-ui with MIT License | 6 votes |
private void decomposeJSONValue(String name, JsonValue val, Map<String, String> map) { if (val.isObject()) { JsonObject obj = val.asObject(); for (String memberName : obj.names()) { this.decomposeJSONValue(name + "." + memberName, obj.get(memberName), map); } } else if (val.isArray()) { JsonArray arr = val.asArray(); for (int i = 0; i < arr.size(); i++) { this.decomposeJSONValue(name + "[" + i + "]", arr.get(i), map); } } else { map.put(name, val.toString()); } }
Example #10
Source File: BoxFile.java From box-java-sdk with Apache License 2.0 | 6 votes |
/** * Locks a file. * * @param expiresAt expiration date of the lock. * @param isDownloadPrevented is downloading of file prevented when locked. * @return the lock returned from the server. */ public BoxLock lock(Date expiresAt, boolean isDownloadPrevented) { String queryString = new QueryStringBuilder().appendParam("fields", "lock").toString(); URL url = FILE_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), queryString, this.getID()); BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "PUT"); JsonObject lockConfig = new JsonObject(); lockConfig.add("type", "lock"); if (expiresAt != null) { lockConfig.add("expires_at", BoxDateFormat.format(expiresAt)); } lockConfig.add("is_download_prevented", isDownloadPrevented); JsonObject requestJSON = new JsonObject(); requestJSON.add("lock", lockConfig); request.setBody(requestJSON.toString()); BoxJSONResponse response = (BoxJSONResponse) request.send(); JsonObject responseJSON = JsonObject.readFrom(response.getJSON()); JsonValue lockValue = responseJSON.get("lock"); JsonObject lockJSON = JsonObject.readFrom(lockValue.toString()); return new BoxLock(lockJSON, this.getAPI()); }
Example #11
Source File: IrdbImporter.java From IrScrutinizer with GNU General Public License v3.0 | 6 votes |
private static void setupManufacturers(boolean verbose) throws IOException { ArrayList<String> newManufacturers = new ArrayList<>(1024); String path = String.format(urlFormatBrands, 1); for (int index = 1; index <= 100 && !path.isEmpty(); index++) { JsonObject o = getJsonObject(path, verbose); JsonValue meta = o.get("meta"); JsonObject metaObject = meta.asObject(); path = metaObject.get("next").asString(); if (verbose) System.err.println("Read page " + metaObject.get("page").asInt()); JsonArray objects = o.get("objects").asArray(); for (JsonValue val : objects) { JsonObject obj = val.asObject(); String brand = obj.get("brand").asString(); if (!newManufacturers.contains(brand)) newManufacturers.add(brand); } } manufacturers = newManufacturers; }
Example #12
Source File: BoxUser.java From box-java-sdk with Apache License 2.0 | 6 votes |
/** * Gets information about all of the group memberships for this user. * Does not support paging. * * <p>Note: This method is only available to enterprise admins.</p> * * @return a collection of information about the group memberships for this user. */ public Collection<BoxGroupMembership.Info> getMemberships() { BoxAPIConnection api = this.getAPI(); URL url = USER_MEMBERSHIPS_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); BoxAPIRequest request = new BoxAPIRequest(api, url, "GET"); BoxJSONResponse response = (BoxJSONResponse) request.send(); JsonObject responseJSON = JsonObject.readFrom(response.getJSON()); int entriesCount = responseJSON.get("total_count").asInt(); Collection<BoxGroupMembership.Info> memberships = new ArrayList<BoxGroupMembership.Info>(entriesCount); JsonArray entries = responseJSON.get("entries").asArray(); for (JsonValue entry : entries) { JsonObject entryObject = entry.asObject(); BoxGroupMembership membership = new BoxGroupMembership(api, entryObject.get("id").asString()); BoxGroupMembership.Info info = membership.new Info(entryObject); memberships.add(info); } return memberships; }
Example #13
Source File: BoxFolder.java From box-java-sdk with Apache License 2.0 | 6 votes |
/** * Gets information about all of the collaborations for this folder. * * @return a collection of information about the collaborations for this folder. */ public Collection<BoxCollaboration.Info> getCollaborations() { BoxAPIConnection api = this.getAPI(); URL url = GET_COLLABORATIONS_URL.build(api.getBaseURL(), this.getID()); BoxAPIRequest request = new BoxAPIRequest(api, url, "GET"); BoxJSONResponse response = (BoxJSONResponse) request.send(); JsonObject responseJSON = JsonObject.readFrom(response.getJSON()); int entriesCount = responseJSON.get("total_count").asInt(); Collection<BoxCollaboration.Info> collaborations = new ArrayList<BoxCollaboration.Info>(entriesCount); JsonArray entries = responseJSON.get("entries").asArray(); for (JsonValue entry : entries) { JsonObject entryObject = entry.asObject(); BoxCollaboration collaboration = new BoxCollaboration(api, entryObject.get("id").asString()); BoxCollaboration.Info info = collaboration.new Info(entryObject); collaborations.add(info); } return collaborations; }
Example #14
Source File: Main.java From jpexs-decompiler with GNU General Public License v3.0 | 6 votes |
private static JsonValue urlGetJson(String getUrl) { try { String proxyAddress = Configuration.updateProxyAddress.get(); URL url = new URL(getUrl); URLConnection uc; if (proxyAddress != null && !proxyAddress.isEmpty()) { int port = 8080; if (proxyAddress.contains(":")) { String[] parts = proxyAddress.split(":"); port = Integer.parseInt(parts[1]); proxyAddress = parts[0]; } uc = url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyAddress, port))); } else { uc = url.openConnection(); } uc.setRequestProperty("User-Agent", ApplicationInfo.shortApplicationVerName); uc.connect(); JsonValue value = Json.parse(new InputStreamReader(uc.getInputStream())); return value; } catch (IOException | NumberFormatException ex) { return null; } }
Example #15
Source File: BoxUser.java From box-java-sdk with Apache License 2.0 | 5 votes |
private Map<String, String> parseTrackingCodes(JsonArray jsonArray) { Map<String, String> result = new HashMap<String, String>(); if (jsonArray == null) { return null; } List<JsonValue> valuesList = jsonArray.values(); for (JsonValue jsonValue : valuesList) { JsonObject object = jsonValue.asObject(); result.put(object.get("name").asString().toString(), object.get("value").asString().toString()); } return result; }
Example #16
Source File: BoundDoubleJsonRule.java From dungeon with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void validate(JsonValue value) { super.validate(value); double doubleValue = value.asDouble(); if (doubleValue < minValue) { throw new IllegalArgumentException(value + " is below the allowed minimum " + minValue + "."); } if (doubleValue > maxValue) { throw new IllegalArgumentException(value + " is above the allowed maximum " + maxValue + "."); } }
Example #17
Source File: IdJsonRule.java From dungeon with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void validate(JsonValue value) { super.validate(value); try { new Id(value.asString()); } catch (IllegalArgumentException invalidValue) { throw new IllegalArgumentException(value + " is not a valid Dungeon id."); } }
Example #18
Source File: IrdbImporter.java From IrScrutinizer with GNU General Public License v3.0 | 5 votes |
public IrdbImporter(String manufacturer, boolean verbose) throws IOException { super(irdbOriginName); this.manufacturer = manufacturer; deviceTypes = new LinkedHashMap<>(16); String path = String.format(urlFormat, URLEncoder.encode(manufacturer, "utf-8"), 1); for (int index = 1; index <= 100 && !path.isEmpty(); index++) { JsonObject o = getJsonObject(path, verbose); JsonValue meta = o.get("meta"); JsonObject metaObject = meta.asObject(); path = metaObject.get("next").asString(); if (verbose) System.err.println("Read page " + metaObject.get("page").asInt()); JsonArray objects = o.get("objects").asArray(); for (JsonValue val : objects) { JsonObject obj = val.asObject(); String deviceType = obj.get("devicetype").asString(); if (!deviceTypes.containsKey(deviceType)) deviceTypes.put(deviceType, new LinkedHashMap<>(8)); Map<ProtocolDeviceSubdevice, Map<String, Long>> devCollection = deviceTypes.get(deviceType); ProtocolDeviceSubdevice pds = new ProtocolDeviceSubdevice(obj); if (pds.getProtocol() == null) { System.err.println("Null protocol ignored"); continue; } if (!devCollection.containsKey(pds)) devCollection.put(pds, new LinkedHashMap<>(8)); Map<String, Long> cmnds = devCollection.get(pds); long function = parseLong(obj.get("function").asString()); // barfs for illegal String functionName = obj.get("functionname").asString(); if (cmnds.containsKey(functionName)) System.err.println("functionname " + functionName + " more than once present, overwriting"); cmnds.put(functionName, function); } } }
Example #19
Source File: ScopedToken.java From box-java-sdk with Apache License 2.0 | 5 votes |
@Override protected void parseJSONMember(JsonObject.Member member) { String memberName = member.getName(); JsonValue value = member.getValue(); if (memberName.equals("access_token")) { this.accessToken = value.asString(); } else if (memberName.equals("token_type")) { this.tokenType = value.asString(); } else if (memberName.equals("issued_token_type")) { this.issuedTokenType = value.asString(); } else if (memberName.equals("restricted_to")) { this.restrictedTo = value.asArray(); } }
Example #20
Source File: PeriodJsonRuleTest.java From dungeon with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void percentageJsonRuleShouldPassOnValidYearPeriod() { JsonValue oneYear = Json.value("1 year"); JsonValue twoYears = Json.value("2 years"); periodJsonRule.validate(oneYear); periodJsonRule.validate(twoYears); }
Example #21
Source File: BoxJsonObject.java From box-android-sdk with Apache License 2.0 | 5 votes |
public ArrayList<String> getAsStringArray(final String field){ if (mInternalCache.get(field) != null){ return (ArrayList<String>)mInternalCache.get(field); } JsonValue value = getAsJsonValue(field); if (value == null || value.isNull()) { return null; } ArrayList<String> strings = new ArrayList<String>(value.asArray().size()); for (JsonValue member : value.asArray()){ strings.add(member.asString()); } mInternalCache.put(field, strings); return strings; }
Example #22
Source File: BoxJsonObject.java From box-android-sdk with Apache License 2.0 | 5 votes |
public Boolean getAsBoolean(final String field){ JsonValue value = getAsJsonValue(field); if (value == null) { return null; } return value.asBoolean(); }
Example #23
Source File: BoxJSONObject.java From box-java-sdk with Apache License 2.0 | 5 votes |
void addChildObject(String fieldName, BoxJSONObject child) { if (child == null) { this.addPendingChange(fieldName, JsonValue.NULL); } else { this.children.put(fieldName, child); } }
Example #24
Source File: BoxUploadEmail.java From box-java-sdk with Apache License 2.0 | 5 votes |
@Override void parseJSONMember(JsonObject.Member member) { JsonValue value = member.getValue(); String memberName = member.getName(); try { if (memberName.equals("access")) { this.access = Access.fromJSONValue(value.asString()); } else if (memberName.equals("email")) { this.email = value.asString(); } } catch (Exception e) { throw new BoxDeserializationException(memberName, value.toString(), e); } }
Example #25
Source File: FilePane.java From JRemapper with MIT License | 5 votes |
@Listener public void onSaveMapRequest(SaveMapEvent save) { JsonValue value = Mappings.INSTANCE.toMapping(); try { Path path = save.getDestination().toPath(); byte[] content = value.toString(WriterConfig.PRETTY_PRINT).getBytes(StandardCharsets.UTF_8); Files.write(path, content, StandardOpenOption.CREATE); } catch (Exception e) { e.printStackTrace(); } }
Example #26
Source File: TslintHelper.java From typescript.java with MIT License | 5 votes |
private static Location createLocation(JsonValue value) { if (value == null || !value.isObject()) { return null; } JsonObject loc = value.asObject(); return new Location(loc.getInt("line", -1), loc.getInt("character", -1), loc.getInt("position", -1)); }
Example #27
Source File: JsonConfig.java From ServerSync with GNU General Public License v3.0 | 5 votes |
private static int getInt(JsonObject root, String name) throws IOException { JsonValue jsv = root.get(name); if (jsv.isNull()) { throw new IOException(String.format("No %s value present in configuration file", name)); } if (!jsv.isNumber()) { throw new IOException(String.format("Invalid value for %s, expected integer", name)); } return jsv.asInt(); }
Example #28
Source File: MetadataTemplate.java From box-java-sdk with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override void parseJSONMember(JsonObject.Member member) { JsonValue value = member.getValue(); String memberName = member.getName(); if (memberName.equals("id")) { this.id = value.asString(); } else if (memberName.equals("key")) { this.key = value.asString(); } }
Example #29
Source File: EventStream.java From box-java-sdk with Apache License 2.0 | 5 votes |
@Override public void run() { long position = this.initialPosition; while (!Thread.interrupted()) { if (this.server.getRemainingRetries() == 0) { this.server = new RealtimeServerConnection(EventStream.this.api); } if (this.server.waitForChange(position)) { if (Thread.interrupted()) { return; } BoxAPIRequest request = new BoxAPIRequest(EventStream.this.api, EVENT_URL.buildAlpha(EventStream.this.api.getBaseURL(), position), "GET"); BoxJSONResponse response = (BoxJSONResponse) request.send(); JsonObject jsonObject = JsonObject.readFrom(response.getJSON()); JsonArray entriesArray = jsonObject.get("entries").asArray(); for (JsonValue entry : entriesArray) { BoxEvent event = new BoxEvent(EventStream.this.api, entry.asObject()); EventStream.this.notifyEvent(event); } position = jsonObject.get("next_stream_position").asLong(); EventStream.this.notifyNextPosition(position); try { // Delay re-polling to avoid making too many API calls // Since duplicate events may appear in the stream, without any delay added // the stream can make 3-5 requests per second and not produce any new // events. A short delay between calls balances latency for new events // and the risk of hitting rate limits. Thread.sleep(EventStream.this.pollingDelay); } catch (InterruptedException ex) { return; } } } }
Example #30
Source File: BoxLock.java From box-java-sdk with Apache License 2.0 | 5 votes |
@Override protected void parseJSONMember(JsonObject.Member member) { super.parseJSONMember(member); String memberName = member.getName(); JsonValue value = member.getValue(); try { if (memberName.equals("type")) { this.type = value.asString(); } else if (memberName.equals("expires_at")) { this.expiresAt = BoxDateFormat.parse(value.asString()); } else if (memberName.equals("is_download_prevented")) { this.isDownloadPrevented = value.asBoolean(); } else if (memberName.equals("created_by")) { JsonObject userJSON = value.asObject(); if (this.createdBy == null) { String userID = userJSON.get("id").asString(); BoxUser user = new BoxUser(this.api, userID); this.createdBy = user.new Info(userJSON); } else { this.createdBy.update(userJSON); } } else if (memberName.equals("created_at")) { this.createdAt = BoxDateFormat.parse(value.asString()); } else if (memberName.equals("id")) { this.id = value.toString(); } } catch (Exception e) { throw new BoxDeserializationException(memberName, value.toString(), e); } }