Java Code Examples for javax.json.JsonObject#isNull()
The following examples show how to use
javax.json.JsonObject#isNull() .
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: JsonFormatterTest.java From jboss-logmanager-ext with Apache License 2.0 | 6 votes |
private static Map<String, String> getMap(final JsonObject json, final Key key) { final String name = getKey(key); if (json.containsKey(name) && !json.isNull(name)) { final Map<String, String> result = new LinkedHashMap<>(); final JsonObject mdcObject = json.getJsonObject(name); for (String k : mdcObject.keySet()) { final JsonValue value = mdcObject.get(k); if (value.getValueType() == ValueType.STRING) { result.put(k, value.toString().replace("\"", "")); } else { result.put(k, value.toString()); } } return result; } return Collections.emptyMap(); }
Example 2
Source File: WeiboStatus.java From albert with MIT License | 6 votes |
public static StatusWapper constructWapperStatus(JsonObject res) throws WeiboException { // JsonObject jsonStatus = res.asJsonObject(); // asJsonArray(); JsonObject jsonStatus = res; JsonArray statuses = null; try { if (!jsonStatus.isNull("statuses")) { statuses = jsonStatus.getJsonArray("statuses"); } int size = statuses.size(); List<WeiboStatus> status = new ArrayList<WeiboStatus>(size); for (int i = 0; i < size; i++) { status.add(new WeiboStatus(statuses.getJsonObject(i))); } long previousCursor = jsonStatus.getJsonNumber("previous_cursor").longValue(); long nextCursor = jsonStatus.getJsonNumber("next_cursor").longValue(); long totalNumber = jsonStatus.getJsonNumber("total_number").longValue(); String hasvisible = String.valueOf(jsonStatus.getBoolean("hasvisible")); return new StatusWapper(status, previousCursor, nextCursor, totalNumber, hasvisible); } catch (JsonException jsone) { throw new WeiboException(jsone); } }
Example 3
Source File: SpringCloudRelease.java From spring-cloud-release-tools with Apache License 2.0 | 6 votes |
@Override @Cacheable("milestoneDueDate") public Milestone getMilestoneDueDate(String name) throws SpringCloudMilestoneNotFoundException, IOException { Iterable<com.jcabi.github.Milestone> milestones = getMilestonesFromGithub(); for (com.jcabi.github.Milestone milestone : milestones) { JsonObject json = milestone.json(); if (json.getString("title").equalsIgnoreCase(name)) { if (json.isNull("due_on")) { return new Milestone("No Due Date"); } else { Instant instant = Instant.parse(json.getString("due_on")); return new Milestone(LocalDateTime .ofInstant(instant, ZoneId.of(ZoneOffset.UTC.getId())) .toLocalDate().toString()); } } } throw new SpringCloudMilestoneNotFoundException(name); }
Example 4
Source File: GeoJsonReader.java From geojson with Apache License 2.0 | 6 votes |
private Map<String, String> getTags(final JsonObject feature) { final Map<String, String> tags = new TreeMap<>(); if (feature.containsKey(PROPERTIES) && !feature.isNull(PROPERTIES)) { JsonValue properties = feature.get(PROPERTIES); if(properties != null && properties.getValueType().equals(JsonValue.ValueType.OBJECT)) { for (Map.Entry<String, JsonValue> stringJsonValueEntry : properties.asJsonObject().entrySet()) { final JsonValue value = stringJsonValueEntry.getValue(); if (value instanceof JsonString) { tags.put(stringJsonValueEntry.getKey(), ((JsonString) value).getString()); } else if (value instanceof JsonStructure) { Logging.warn( "The GeoJSON contains an object with property '" + stringJsonValueEntry.getKey() + "' whose value has the unsupported type '" + value.getClass().getSimpleName() + "'. That key-value pair is ignored!" ); } else if (value.getValueType() != JsonValue.ValueType.NULL) { tags.put(stringJsonValueEntry.getKey(), value.toString()); } } } } return tags; }
Example 5
Source File: JsonFormatterTest.java From jboss-logmanager-ext with Apache License 2.0 | 5 votes |
private static void compareLogstash(final ExtLogRecord record, final String jsonString, final int version) { final JsonReader reader = Json.createReader(new StringReader(jsonString)); final JsonObject json = reader.readObject(); compare(record, json, null); final String name = "@version"; int foundVersion = 0; if (json.containsKey(name) && !json.isNull(name)) { foundVersion = json.getInt(name); } Assert.assertEquals(version, foundVersion); }
Example 6
Source File: JsonFormatterTest.java From jboss-logmanager-ext with Apache License 2.0 | 5 votes |
private static String getString(final JsonObject json, final Key key) { final String name = getKey(key); if (json.containsKey(name) && !json.isNull(name)) { return json.getString(name); } return null; }
Example 7
Source File: JsonFormatterTest.java From jboss-logmanager-ext with Apache License 2.0 | 5 votes |
private static long getLong(final JsonObject json, final Key key) { final String name = getKey(key); if (json.containsKey(name) && !json.isNull(name)) { return json.getJsonNumber(name).longValue(); } return 0L; }
Example 8
Source File: JsonFormatterTest.java From jboss-logmanager-ext with Apache License 2.0 | 5 votes |
private static int getInt(final JsonObject json, final Key key) { final String name = getKey(key); if (json.containsKey(name) && !json.isNull(name)) { return json.getInt(name); } return 0; }
Example 9
Source File: GlobalContext.java From logbook with MIT License | 5 votes |
/** * 任務を更新します * * @param data */ private static void doQuest(Data data) { try { JsonObject apidata = data.getJsonObject().getJsonObject("api_data"); if (!apidata.isNull("api_list")) { JsonArray apilist = apidata.getJsonArray("api_list"); for (JsonValue value : apilist) { if (value instanceof JsonObject) { JsonObject questobject = (JsonObject) value; // 任務を作成 QuestDto quest = new QuestDto(); quest.setNo(questobject.getInt("api_no")); quest.setCategory(questobject.getInt("api_category")); quest.setType(questobject.getInt("api_type")); quest.setState(questobject.getInt("api_state")); quest.setTitle(questobject.getString("api_title")); quest.setDetail(questobject.getString("api_detail")); JsonArray material = questobject.getJsonArray("api_get_material"); quest.setFuel(material.getJsonNumber(0).toString()); quest.setAmmo(material.getJsonNumber(1).toString()); quest.setMetal(material.getJsonNumber(2).toString()); quest.setBauxite(material.getJsonNumber(3).toString()); quest.setBonusFlag(questobject.getInt("api_bonus_flag")); quest.setProgressFlag(questobject.getInt("api_progress_flag")); questMap.put(quest.getNo(), quest); } } } addConsole("任務を更新しました"); } catch (Exception e) { LoggerHolder.LOG.warn("任務を更新しますに失敗しました", e); LoggerHolder.LOG.warn(data); } }
Example 10
Source File: JsonUtil.java From geoportal-server-harvester with Apache License 2.0 | 5 votes |
/** * Gets a string value. * @param jso the json object * @param name the property name * @return the stgring value */ public static String getString(JsonObject jso, String name) { if (jso != null && jso.containsKey(name) && !jso.isNull(name)) { JsonValue v = jso.get(name); if (v.getValueType().equals(ValueType.STRING)) { return jso.getString(name); } else if (v.getValueType().equals(ValueType.NUMBER)) { // TODO Convert to string? } } return null; }
Example 11
Source File: GlobalContext.java From logbook with MIT License | 4 votes |
/** * 建造(入手)情報を更新します * @param data */ private static void doGetship(Data data) { try { JsonObject apidata = data.getJsonObject().getJsonObject("api_data"); String dock = data.getField("api_kdock_id"); // 艦娘の装備を追加します if (!apidata.isNull("api_slotitem")) { JsonArray slotitem = apidata.getJsonArray("api_slotitem"); for (int i = 0; i < slotitem.size(); i++) { JsonObject object = (JsonObject) slotitem.get(i); int typeid = object.getJsonNumber("api_slotitem_id").intValue(); Long id = object.getJsonNumber("api_id").longValue(); ItemDto item = Item.get(typeid); if (item != null) { ItemContext.get().put(id, item); } } } // 艦娘を追加します JsonObject apiShip = apidata.getJsonObject("api_ship"); ShipDto ship = new ShipDto(apiShip); ShipContext.get().put(Long.valueOf(ship.getId()), ship); // 投入資源を取得する ResourceDto resource = getShipResource.get(dock); if (resource == null) { resource = KdockConfig.load(dock); } GetShipDto dto = new GetShipDto(ship, resource); getShipList.add(dto); CreateReportLogic.storeCreateShipReport(dto); // 投入資源を除去する getShipResource.remove(dock); KdockConfig.remove(dock); addConsole("建造(入手)情報を更新しました"); } catch (Exception e) { LoggerHolder.LOG.warn("建造(入手)情報を更新しますに失敗しました", e); LoggerHolder.LOG.warn(data); } }
Example 12
Source File: HFCAClient.java From fabric-sdk-java with Apache License 2.0 | 4 votes |
private String revokeInternal(User revoker, String revokee, String reason, boolean genCRL) throws RevocationException, InvalidArgumentException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); } logger.debug(format("revoke revoker: %s, revokee: %s, reason: %s", revoker, revokee, reason)); if (Utils.isNullOrEmpty(revokee)) { throw new InvalidArgumentException("revokee user is not set"); } if (revoker == null) { throw new InvalidArgumentException("revoker is not set"); } try { setUpSSL(); // build request body RevocationRequest req = new RevocationRequest(caName, revokee, null, null, reason, genCRL); String body = req.toJson(); // send revoke request JsonObject resp = httpPost(url + HFCA_REVOKE, body, revoker); logger.debug(format("revoke revokee: %s done.", revokee)); if (genCRL) { if (resp.isEmpty()) { throw new RevocationException("Failed to return CRL, revoke response is empty"); } if (resp.isNull("CRL")) { throw new RevocationException("Failed to return CRL"); } return resp.getString("CRL"); } return null; } catch (Exception e) { logger.error(e.getMessage(), e); throw new RevocationException("Error while revoking the user. " + e.getMessage(), e); } }
Example 13
Source File: Loader.java From karaf-decanter with Apache License 2.0 | 4 votes |
static public List<Rule> load(Dictionary<String, Object> configuration) { List<Rule> rules = new ArrayList<>(); if (configuration == null) { return rules; } Enumeration<String> keys = configuration.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (key.startsWith("rule.")) { Rule rule = new Rule(); rule.setName(key.substring("rule.".length())); String ruleDefinition = (String) configuration.get(key); ruleDefinition = ruleDefinition.replaceAll("'", "\""); if (ruleDefinition != null && !ruleDefinition.isEmpty()) { JsonReader jsonReader = Json.createReader(new StringReader(ruleDefinition)); JsonObject jsonObject = jsonReader.readObject(); if (jsonObject.isNull("condition")) { LOGGER.error("Can't load rule {} as condition is null", ruleDefinition); } else { rule.setCondition(jsonObject.getString("condition")); if (jsonObject.get("period") == null) { rule.setPeriod(null); } else { rule.setPeriod(jsonObject.getString("period")); } if (jsonObject.get("level") == null) { rule.setLevel("WARN"); } else { rule.setLevel(jsonObject.getString("level")); } if (jsonObject.get("recoverable") == null) { rule.setRecoverable(false); } else { rule.setRecoverable(jsonObject.getBoolean("recoverable")); } rules.add(rule); } } } } return rules; }
Example 14
Source File: NetworkMessageResponse.java From vicinity-gateway-api with GNU General Public License v3.0 | 4 votes |
/** * Takes the JSON object that came over the network and fills necessary fields with values. * * @param json JSON to parse. * @return True if parsing was successful, false otherwise. */ private boolean parseJson(JsonObject json){ // first check out whether or not the message has everything it is supposed to have and stop if not if ( !json.containsKey(ATTR_MESSAGETYPE) || !json.containsKey(ATTR_REQUESTID) || !json.containsKey(ATTR_SOURCEOID) || !json.containsKey(ATTR_DESTINATIONOID) || !json.containsKey(ATTR_ERROR) || !json.containsKey(ATTR_RESPONSECODE) || !json.containsKey(ATTR_RESPONSECODEREASON) || !json.containsKey(ATTR_RESPONSEBODY) || !json.containsKey(ATTR_RESPONSEBODYSUPPLEMENT)) { return false; } // load values from JSON try { messageType = json.getInt(NetworkMessage.ATTR_MESSAGETYPE); requestId = json.getInt(NetworkMessage.ATTR_REQUESTID); error = json.getBoolean(ATTR_ERROR); responseCode = json.getInt(ATTR_RESPONSECODE); // null values are special cases in JSON, they get transported as "null" string... if (!json.isNull(ATTR_RESPONSECODEREASON)) { responseCodeReason = json.getString(ATTR_RESPONSECODEREASON); } if (!json.isNull(ATTR_SOURCEOID)) { sourceOid = json.getString(ATTR_SOURCEOID); } if (!json.isNull(ATTR_DESTINATIONOID)) { destinationOid = json.getString(ATTR_DESTINATIONOID); } if (!json.isNull(ATTR_CONTENTTYPE)) { contentType = json.getString(ATTR_CONTENTTYPE); } if (!json.isNull(ATTR_RESPONSEBODY)) { responseBody = json.getString(ATTR_RESPONSEBODY); } if (!json.isNull(ATTR_RESPONSEBODYSUPPLEMENT)) { responseBodySupplement = json.getString(ATTR_RESPONSEBODYSUPPLEMENT); } } catch (Exception e) { logger.severe("NetworkMessageResponse: Exception while parsing NetworkMessageResponse: " + e.getMessage()); return false; } // process non primitives sourceOid = removeQuotes(sourceOid); destinationOid = removeQuotes(destinationOid); responseCodeReason = removeQuotes(responseCodeReason); contentType = removeQuotes(contentType); responseBody = removeQuotes(responseBody); responseBodySupplement = removeQuotes(responseBodySupplement); return true; }
Example 15
Source File: NetworkMessageEvent.java From vicinity-gateway-api with GNU General Public License v3.0 | 4 votes |
/** * Takes the JSON object and fills necessary fields with values. * * @param json JSON to parse. * @return True if parsing was successful, false otherwise. */ private boolean parseJson(JsonObject json){ // first check out whether or not the message has everything it is supposed to have and stop if not if ( !json.containsKey(ATTR_MESSAGETYPE) || !json.containsKey(ATTR_SOURCEOID) || !json.containsKey(ATTR_EVENTID) || !json.containsKey(ATTR_EVENTBODY) || !json.containsKey(ATTR_PARAMETERS)) { return false; } // prepare objects for parameters and attributes JsonObject parametersJson = null; // load values from JSON try { messageType = json.getInt(NetworkMessage.ATTR_MESSAGETYPE); // null values are special cases in JSON, they get transported as "null" string and must be treated // separately if (!json.isNull(ATTR_SOURCEOID)) { sourceOid = json.getString(ATTR_SOURCEOID); } if (!json.isNull(ATTR_EVENTID)) { eventId = json.getString(ATTR_EVENTID); } if (!json.isNull(ATTR_EVENTBODY)) { eventBody = json.getString(ATTR_EVENTBODY); } if (!json.isNull(ATTR_PARAMETERS)) { parametersJson = json.getJsonObject(ATTR_PARAMETERS); } if (!json.isNull(ATTR_REQUESTID)) { requestId = json.getInt(ATTR_REQUESTID); } } catch (Exception e) { logger.severe("NetworkMessageEvent: Exception while parsing NetworkMessageEvent: " + e.getMessage()); return false; } // process non primitives, start with strings sourceOid = removeQuotes(sourceOid); eventId = removeQuotes(eventId); eventBody = removeQuotes(eventBody); // important if (sourceOid == null || eventId == null) { return false; } // here the parameters will be stored during reading Set<Entry<String,JsonValue>> entrySet; String stringValue; // this can be null, but that should not be dangerous. we'll just leave the set clear in such case if (parametersJson != null){ entrySet = parametersJson.entrySet(); for (Entry<String, JsonValue> entry : entrySet) { // we have to remove the quotes stringValue = removeQuotes(entry.getValue().toString()); // and the null value got transported more like string... we have to make a rule for it if (stringValue.equals("null")){ parameters.put(entry.getKey(), null); } else { parameters.put(entry.getKey(), stringValue); } } } return true; }
Example 16
Source File: WeiboStatus.java From albert with MIT License | 4 votes |
private void constructJson(JsonObject json) throws WeiboException { try { createdAt = WeiboResponseUtil.parseDate(json.getString("created_at"), "EEE MMM dd HH:mm:ss z yyyy"); id = json.getJsonNumber("id").longValue(); mid = json.getString("mid"); idstr = json.getString("idstr"); text = WeiboResponseUtil.withNonBmpStripped(json.getString("text")); if (!json.getString("source").isEmpty()) { source = new Source(WeiboResponseUtil.withNonBmpStripped(json.getString("source"))); } inReplyToStatusId = json.getString("in_reply_to_status_id"); inReplyToUserId = json.getString("in_reply_to_user_id"); inReplyToScreenName = json.getString("in_reply_to_screen_name"); favorited = json.getBoolean("favorited"); truncated = json.getBoolean("truncated"); thumbnailPic = JsonUtil.getString(json, "thumbnail_pic"); bmiddlePic = JsonUtil.getString(json, "bmiddle_pic"); originalPic = JsonUtil.getString(json, "original_pic"); repostsCount = json.getInt("reposts_count"); commentsCount = json.getInt("comments_count"); if (json.containsKey("annotations")) annotations = json.getJsonArray("annotations").toString(); if (!json.isNull("user")) weiboUser = new WeiboUser(json.getJsonObject("user")); if (json.containsKey("retweeted_status")) { retweetedStatus = new WeiboStatus(json.getJsonObject("retweeted_status")); } mlevel = json.getInt("mlevel"); if (json.isNull("geo")) { geo = null; } else { geo = json.getJsonObject("geo").toString(); } if (geo != null && !"".equals(geo) && !"null".equals(geo)) { getGeoInfo(geo); } if (!json.isNull("visible")) { visible = new Visible(json.getJsonObject("visible")); } } catch (JsonException je) { throw new WeiboException(je.getMessage() + ":" + json.toString(), je); } }
Example 17
Source File: GraphQlClientProxy.java From smallrye-graphql with Apache License 2.0 | 4 votes |
private JsonObject readResponse(String request, String response) { JsonObject responseJson = jsonReaderFactory.createReader(new StringReader(response)).readObject(); if (responseJson.containsKey("errors") && !responseJson.isNull("errors")) throw new GraphQlClientException("errors from service: " + responseJson.getJsonArray("errors") + ":\n " + request); return responseJson; }