org.codehaus.jettison.json.JSONObject.isNull()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中org.codehaus.jettison.json.JSONObject.isNull()方法的一些代码示例,展示了JSONObject.isNull()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.isNull()方法的具体详情如下:
包路径:org.codehaus.jettison.json.JSONObject
类名称:JSONObject
方法名:isNull

JSONObject.isNull介绍

[英]Determine if the value associated with the key is null or if there is no value.
[中]确定与键关联的值是null还是没有值。

代码示例

代码示例来源:origin: ORCID/ORCID-Source

public static Boolean extractBoolean(JSONObject record, String key) {
  //this should not happen
  if (record.isNull(key)) {
    return null;
  }
  try {
    return record.getBoolean(key);
  } catch (JSONException e) {
    throw new RuntimeException("Error extracting boolean from json", e);
  }
}

代码示例来源:origin: ORCID/ORCID-Source

public static JSONObject extractObject(JSONObject parent, String key) {
  if (parent.isNull(key)) {
    return null;
  }
  try {
    return parent.getJSONObject(key);
  } catch (JSONException e) {
    throw new RuntimeException("Error extracting json object", e);
  }
}

代码示例来源:origin: ORCID/ORCID-Source

public static int extractInt(JSONObject record, String key) {
  if (record.isNull(key)) {
    return -1;
  }
  try {
    return record.getInt(key);
  } catch (JSONException e) {
    throw new RuntimeException("Error extracting int from json", e);
  }
}

代码示例来源:origin: ORCID/ORCID-Source

public static String extractString(JSONObject record, String key) {
  if (record.isNull(key)) {
    return null;
  }
  try {
    return record.getString(key);
  } catch (JSONException e) {
    throw new RuntimeException("Error extracting string from json", e);
  }
}

代码示例来源:origin: org.apache.apex/apex-engine

@POST // not supported by WebAppProxyServlet, can only be called directly
@Path(PATH_PHYSICAL_PLAN_OPERATORS + "/{operatorId:\\d+}/properties")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject setPhysicalOperatorProperties(JSONObject request, @PathParam("operatorId") int operatorId)
{
 init();
 JSONObject response = new JSONObject();
 try {
  @SuppressWarnings("unchecked")
  Iterator<String> keys = request.keys();
  while (keys.hasNext()) {
   String key = keys.next();
   String val = request.isNull(key) ? null : request.getString(key);
   dagManager.setPhysicalOperatorProperty(operatorId, key, val);
  }
 } catch (JSONException ex) {
  LOG.warn("Got JSON Exception: ", ex);
 }
 return response;
}

代码示例来源:origin: org.apache.apex/apex-engine

@POST // not supported by WebAppProxyServlet, can only be called directly
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/properties")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject setOperatorProperties(JSONObject request, @PathParam("operatorName") String operatorName)
{
 init();
 OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
 if (logicalOperator == null) {
  throw new NotFoundException();
 }
 JSONObject response = new JSONObject();
 try {
  @SuppressWarnings("unchecked")
  Iterator<String> keys = request.keys();
  while (keys.hasNext()) {
   String key = keys.next();
   String val = request.isNull(key) ? null : request.getString(key);
   LOG.debug("Setting property for {}: {}={}", operatorName, key, val);
   dagManager.setOperatorProperty(operatorName, key, val);
  }
 } catch (JSONException ex) {
  LOG.warn("Got JSON Exception: ", ex);
 } catch (Exception ex) {
  LOG.error("Caught exception: ", ex);
  throw new RuntimeException(ex);
 }
 return response;
}

代码示例来源:origin: apache/stanbol

Collection<String> dataTypes = parseDatatypeProperty(jConstraint, nsPrefixService);
final List<Object> valueList;
if(jConstraint.has("value") && !jConstraint.isNull("value")){
  Object value = jConstraint.get("value");
  if(value instanceof JSONArray){

代码示例来源:origin: apache/stanbol

private static Constraint parseConstraint(JSONObject jConstraint, NamespacePrefixService nsPrefixService) throws JSONException {
  final Constraint constraint;
  if(jConstraint.has("type") && !jConstraint.isNull("type")) {
    String type = jConstraint.getString("type");

代码示例来源:origin: batfish/batfish

@VisibleForTesting
static String readQuestionTemplate(Path file, Map<String, String> templates)
  throws JSONException, IOException {
 String questionText = CommonUtil.readFile(file);
 JSONObject questionObj = new JSONObject(questionText);
 if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) {
  JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE);
  String instanceDataStr = instanceDataObj.toString();
  InstanceData instanceData =
    BatfishObjectMapper.mapper().readValue(instanceDataStr, InstanceData.class);
  String name = instanceData.getInstanceName();
  String key = name.toLowerCase();
  if (templates.containsKey(key) && _logger != null) {
   _logger.warnf(
     "Found duplicate template having instance name %s, only the last one in the list of templatedirs will be loaded\n",
     name);
  }
  templates.put(key, questionText);
  return name;
 } else {
  throw new BatfishException(String.format("Question in file:%s has no instance name", file));
 }
}

代码示例来源:origin: eclipse-ee4j/glassfish

private boolean sameNil(JSONObject parent, String name) {
  trace("comparing object nil property " + name);
  indent();
  try {
    if (parent.isNull(name)) {
      trace("same nil");
      return true;
    } else {
      trace("different nil");
      return false;
    }
  } finally {
    undent();
  }
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

private void verifyQueueOrder(JSONObject json, String realOrder)
  throws Exception {
 String order = "";
 if (!json.isNull("root")) {
  JSONObject root = json.getJSONObject("root");
  order = root.getString("name") + "-" + getQueueOrder(root);
 }
 assertEquals("Order of queue is wrong",
   order.substring(0, order.length() - 1), realOrder);
}

代码示例来源:origin: GluuFederation/oxAuth

private JSONObject updateKeys(JSONObject jwks) throws Exception {
  JSONObject jsonObject = AbstractCryptoProvider.generateJwks(appConfiguration.getKeyRegenerationInterval(),
      appConfiguration.getIdTokenLifetime(), appConfiguration);
  JSONArray keys = jwks.getJSONArray(JSON_WEB_KEY_SET);
  for (int i = 0; i < keys.length(); i++) {
    JSONObject key = keys.getJSONObject(i);
    if (key.has(EXPIRATION_TIME) && !key.isNull(EXPIRATION_TIME)) {
      GregorianCalendar now = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
      GregorianCalendar expirationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
      expirationDate.setTimeInMillis(key.getLong(EXPIRATION_TIME));
      if (expirationDate.before(now)) {
        // The expired key is not added to the array of keys
        log.debug("Removing JWK: {}, Expiration date: {}", key.getString(KEY_ID),
            key.getString(EXPIRATION_TIME));
        AbstractCryptoProvider cryptoProvider = CryptoProviderFactory.getCryptoProvider(appConfiguration);
        cryptoProvider.deleteKey(key.getString(KEY_ID));
      } else {
        jsonObject.getJSONArray(JSON_WEB_KEY_SET).put(key);
      }
    } else {
      GregorianCalendar expirationTime = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
      expirationTime.add(GregorianCalendar.HOUR, appConfiguration.getKeyRegenerationInterval());
      expirationTime.add(GregorianCalendar.SECOND, appConfiguration.getIdTokenLifetime());
      key.put(EXPIRATION_TIME, expirationTime.getTimeInMillis());
      jsonObject.getJSONArray(JSON_WEB_KEY_SET).put(key);
    }
  }
  return jsonObject;
}

代码示例来源:origin: batfish/batfish

/**
 * Loads question from a JSON
 *
 * @param questionText Question JSON Text
 * @param questionSource JSON key of question or file path of JSON
 * @return question loaded as a {@link JSONObject}
 * @throws BatfishException if question does not have instanceName or question cannot be parsed
 */
static JSONObject loadQuestionFromText(String questionText, String questionSource) {
 try {
  JSONObject questionObj = new JSONObject(questionText);
  if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) {
   JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE);
   String instanceDataStr = instanceDataObj.toString();
   InstanceData instanceData =
     BatfishObjectMapper.mapper()
       .readValue(instanceDataStr, new TypeReference<InstanceData>() {});
   validateInstanceData(instanceData);
   return questionObj;
  } else {
   throw new BatfishException(
     String.format("Question in %s has no instance data", questionSource));
  }
 } catch (JSONException | IOException e) {
  throw new BatfishException("Failed to process question", e);
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

private String getQueueOrder(JSONObject node) throws Exception {
 if (!node.isNull("children")) {
  Object children = node.get("children");
  if (children.getClass() == JSONObject.class) {
   if (!((JSONObject) children).isNull("appPriority")) {
    return "";
   }
   return ((JSONObject) children).getString("name") + "-" + getQueueOrder(
     (JSONObject) children);
  } else if (children.getClass() == JSONArray.class) {
   String order = "";
   for (int i = 0; i < ((JSONArray) children).length(); i++) {
    JSONObject child = (JSONObject) ((JSONArray) children).get(i);
    if (!child.isNull("appPriority")) {
     return "";
    }
    order += (child.getString("name") + "-" + getQueueOrder(child));
   }
   return order;
  }
 }
 return "";
}

代码示例来源:origin: GluuFederation/oxAuth

public UserInfoMember(JSONObject jsonObject) throws JSONException {
  claims = new ArrayList<Claim>();
  for (Iterator<String> iterator = jsonObject.keys(); iterator.hasNext(); ) {
    String claimName = iterator.next();
    ClaimValue claimValue = null;
    if (jsonObject.isNull(claimName)) {
      claimValue = ClaimValue.createNull();
    } else {
      JSONObject claimValueJsonObject = jsonObject.getJSONObject(claimName);
      if (claimValueJsonObject.has("essential")) {
        boolean essential = claimValueJsonObject.getBoolean("essential");
        claimValue = ClaimValue.createEssential(essential);
      } else if (claimValueJsonObject.has("values")) {
        JSONArray claimValueJsonArray = claimValueJsonObject.getJSONArray("values");
        List<String> claimValueArr = Util.asList(claimValueJsonArray);
        claimValue = ClaimValue.createValueList(claimValueArr);
      }
    }
    Claim claim = new Claim(claimName, claimValue);
    claims.add(claim);
  }
  preferredLocales = new ArrayList<String>();
  if (jsonObject.has("preferred_locales")) {
    JSONArray preferredLocalesJsonArray = jsonObject.getJSONArray("preferred_locales");
    for (int i = 0; i < preferredLocalesJsonArray.length(); i++) {
      preferredLocales.add(preferredLocalesJsonArray.getString(i));
    }
  }
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

private void verifyNumberOfAllocations(JSONObject json, int realValue)
  throws Exception {
 if (json.isNull("allocations")) {
  assertEquals("Number of allocations is wrong", 0, realValue);
 } else {
  Object object = json.get("allocations");
  if (object.getClass() == JSONObject.class) {
   assertEquals("Number of allocations is wrong", 1, realValue);
  } else if (object.getClass() == JSONArray.class) {
   assertEquals("Number of allocations is wrong in: " + object,
     ((JSONArray) object).length(), realValue);
  }
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

private void verifyNumberOfAllocationAttempts(JSONObject allocation,
  int realValue) throws Exception {
 if (allocation.isNull("allocationAttempt")) {
  assertEquals("Number of allocation attempts is wrong", 0, realValue);
 } else {
  Object object = allocation.get("allocationAttempt");
  if (object.getClass() == JSONObject.class) {
   assertEquals("Number of allocations attempts is wrong", 1, realValue);
  } else if (object.getClass() == JSONArray.class) {
   assertEquals("Number of allocations attempts is wrong",
     ((JSONArray) object).length(), realValue);
  }
 }
}

代码示例来源:origin: GluuFederation/oxAuth

public IdTokenMember(JSONObject jsonObject) throws JSONException {
  claims = new ArrayList<Claim>();
  for (Iterator<String> iterator = jsonObject.keys(); iterator.hasNext(); ) {
    String claimName = iterator.next();
    ClaimValue claimValue = null;
    if (claimName != null && claimName.equals("max_age") && jsonObject.has("max_age")) {
      maxAge = jsonObject.getInt("max_age");
    } else if (jsonObject.isNull(claimName)) {
      claimValue = ClaimValue.createNull();
    } else {
      JSONObject claimValueJsonObject = jsonObject.getJSONObject(claimName);
      if (claimValueJsonObject.has("essential")) {
        boolean essential = claimValueJsonObject.getBoolean("essential");
        claimValue = ClaimValue.createEssential(essential);
      } else if (claimValueJsonObject.has("values")) {
        JSONArray claimValueJsonArray = claimValueJsonObject.getJSONArray("values");
        List<String> claimValueArr = Util.asList(claimValueJsonArray);
        claimValue = ClaimValue.createValueList(claimValueArr);
      } else if (claimValueJsonObject.has("value")) {
        String value = claimValueJsonObject.getString("value");
        claimValue = ClaimValue.createSingleValue(value);
      }
    }
    Claim claim = new Claim(claimName, claimValue);
    claims.add(claim);
  }
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

private void verifyNumberOfNodes(JSONObject allocation, int realValue)
  throws Exception {
 if (allocation.isNull("root")) {
  assertEquals("State of allocation is wrong", 0, realValue);
 } else {
  assertEquals("State of allocation is wrong",
    1 + getNumberOfNodes(allocation.getJSONObject("root")), realValue);
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

private int getNumberOfNodes(JSONObject allocation) throws Exception {
 if (!allocation.isNull("children")) {
  Object object = allocation.get("children");
  if (object.getClass() == JSONObject.class) {
   return 1 + getNumberOfNodes((JSONObject) object);
  } else {
   int count = 0;
   for (int i = 0; i < ((JSONArray) object).length(); i++) {
    count += (1 + getNumberOfNodes(
      ((JSONArray) object).getJSONObject(i)));
   }
   return count;
  }
 } else {
  return 0;
 }
}

相关文章