当前位置: 首页>>代码示例>>Java>>正文


Java JsonObject.containsKey方法代码示例

本文整理汇总了Java中javax.json.JsonObject.containsKey方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.containsKey方法的具体用法?Java JsonObject.containsKey怎么用?Java JsonObject.containsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.json.JsonObject的用法示例。


在下文中一共展示了JsonObject.containsKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMixinTypes

import javax.json.JsonObject; //导入方法依赖的package包/类
public void testMixinTypes() throws IOException, JsonException {
    
    // create a node without mixin node types
    final Map <String, String> props = new HashMap <String, String> ();
    props.put("jcr:primaryType","nt:unstructured");
    final String location = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, props);
    
    // assert no mixins
    String content = getContent(location + ".json", CONTENT_TYPE_JSON);
    JsonObject json = JsonUtil.parseObject(content);
    assertFalse("jcr:mixinTypes not expected to be set", json.containsKey("jcr:mixinTypes"));
    
    // add mixin
    props.clear();
    props.put("jcr:mixinTypes", "mix:versionable");
    testClient.createNode(location, props);
    
    content = getContent(location + ".json", CONTENT_TYPE_JSON);
    json = JsonUtil.parseObject(content);
    assertTrue("jcr:mixinTypes expected after setting them", json.containsKey("jcr:mixinTypes"));
    
    Object mixObject = json.get("jcr:mixinTypes");
    assertTrue("jcr:mixinTypes must be an array", mixObject instanceof JsonArray);
    
    JsonArray mix = (JsonArray) mixObject;
    assertTrue("jcr:mixinTypes must have a single entry", mix.size() == 1);
    assertEquals("jcr:mixinTypes must have correct value", "mix:versionable", mix.getString(0));

    // remove mixin
    props.clear();
    props.put("jcr:[email protected]", "-");
    testClient.createNode(location, props);

    content = getContent(location + ".json", CONTENT_TYPE_JSON);
    json = JsonUtil.parseObject(content);
    final boolean noMixins = !json.containsKey("jcr:mixinTypes") || json.getJsonArray("jcr:mixinTypes").size() == 0;
    assertTrue("no jcr:mixinTypes expected after clearing it", noMixins);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:39,代码来源:PostServletUpdateTest.java

示例2: parseAddress

import javax.json.JsonObject; //导入方法依赖的package包/类
@Override
public Address parseAddress(JsonObject json) {
    Address address = new Address();

    JsonObject result = json.getJsonArray("result").getJsonObject(0);

    if (result.containsKey("streetName")) {
        address.setStreet(result.getString("streetName"));
    }
    if (result.containsKey("city")) {
        address.setSettlement(result.getString("city"));
    }
    if (result.containsKey("state")) {
        address.setState(result.getString("state"));
    }
    if (result.containsKey("countryCode")) {
        address.setCountry(result.getString("countryCode"));
    }

    return address;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:22,代码来源:GisgraphyGeocoder.java

示例3: getResponseBody

import javax.json.JsonObject; //导入方法依赖的package包/类
private JsonObject getResponseBody(JsonObject response) {
  JsonObject body = null;
  try {
    body =
        response.containsKey("result")
            ? response.getJsonObject("result")
            : response.getJsonObject("object");
  } catch (Exception e) {
    throw new WebDriverException(e);
  }

  if (body == null) {
    throw new RuntimeException("Error parsting " + response);
  }
  return body;
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:17,代码来源:WebInspectorHelper.java

示例4: User

import javax.json.JsonObject; //导入方法依赖的package包/类
/** Constructor for reading the user from the JSON that was a part of a JAX-RS request. */
public User(JsonObject user) {
  if (user.containsKey(JSON_KEY_USER_ID)) {
    id = user.getString(JSON_KEY_USER_ID);
  }
  this.firstName = user.getString(JSON_KEY_USER_FIRST_NAME, "");
  this.lastName = user.getString(JSON_KEY_USER_LAST_NAME, "");
  this.twitterHandle = user.getString(JSON_KEY_USER_TWITTER_HANDLE, "");
  this.wishListLink = user.getString(JSON_KEY_USER_WISH_LIST_LINK, "");
  this.isTwitterLogin = user.getBoolean(JSON_KEY_USER_TWITTER_LOGIN, false);

  if (user.containsKey(JSON_KEY_USER_NAME)) {
    this.userName = user.getString(JSON_KEY_USER_NAME);
  }
  if (user.containsKey(JSON_KEY_USER_PASSWORD_HASH)) {
    this.passwordHash = user.getString(JSON_KEY_USER_PASSWORD_HASH);
  }
  if (user.containsKey(JSON_KEY_USER_PASSWORD_SALT)) {
    this.passwordSalt = user.getString(JSON_KEY_USER_PASSWORD_SALT);
  }
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:22,代码来源:User.java

示例5: Group

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
 * Create a group based on a JSON Object
 *
 * @param group The JSON Object with group information
 */
public Group(JsonObject group) {
  if (group.containsKey(JSON_KEY_GROUP_ID)) {
    id = group.getString(JSON_KEY_GROUP_ID);
  }
  name = group.getString(JSON_KEY_GROUP_NAME);

  JsonArray jsonMembers = group.getJsonArray(JSON_KEY_MEMBERS_LIST);
  if (jsonMembers != null) {
    members = new String[jsonMembers.size()];
    for (int i = 0; i < jsonMembers.size(); i++) {
      members[i] = jsonMembers.getString(i);
    }
  } else {
    members = new String[0];
  }
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:22,代码来源:Group.java

示例6: getAttachment

import javax.json.JsonObject; //导入方法依赖的package包/类
public static AttachmentDao getAttachment(JsonObject json) {
    
    AttachmentDao ob = new AttachmentDao();
    if(json.containsKey("id") && !json.isNull("id")){
        ob.setId(json.getString("id"));
    }
    if(json.containsKey("description") && !json.isNull("description")){
        ob.setDescription(json.getString("description"));
    }
    if(json.containsKey("filename") && !json.isNull("filename")){
        ob.setFilename(json.getString("filename"));
    }
    if(json.containsKey("mimeType") && !json.isNull("mimeType")){
        ob.setMimeType(json.getString("mimeType"));
    }
    if(json.containsKey("checksum") && !json.isNull("checksum")){
        ob.setChecksum(json.getString("checksum"));
    }
    if(json.containsKey("size") && !json.isNull("size")){
        ob.setSize(json.getInt("size"));
    }
    return ob;
}
 
开发者ID:avraampiperidis,项目名称:DiavgeiaUtils,代码行数:24,代码来源:DecisionDaoProviderBuilder.java

示例7: getKey

import javax.json.JsonObject; //导入方法依赖的package包/类
private boolean getKey() throws IOException {
    String resp = makeQuery(POST, PROTOCOL + bridge.getIp() + API, IDENTBODY);
    if (resp != null) {
        JsonReader reader = Json.createReader(new StringReader(resp));
        JsonArray arr = reader.readArray();
        JsonObject obj = arr.getJsonObject(0);
        if (obj.containsKey("success")) {
            JsonObject success = obj.getJsonObject("success");
            bridge.setKey(success.getString("username"));
            LOG.info("Got key from bridge");
            return true;
        }

    }
    return false;
}
 
开发者ID:dainesch,项目名称:HueSense,代码行数:17,代码来源:HueComm.java

示例8: postJson

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
 *
 * @param content
 * @return
 */
@POST
@Consumes(javax.ws.rs.core.MediaType.APPLICATION_JSON)
@Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)
public String postJson(String content) {
    JsonObject announcement;
    try (JsonReader reader = Json.createReader(new StringReader(content))) {
        announcement = reader.readObject();
    }
    // Simple check for parts
        Logger.getLogger(Message.class.getName()).log(Level.INFO, announcement.toString());
    // ERRORS
    if (announcement.containsKey("@id")) {
        // There should not be one already; these are new annoucements.
        Response.status(HttpURLConnection.HTTP_BAD_REQUEST).entity("POST is for new annoucements only.").build();
        return "{\"error\":\"Property '@id' indicates this is not a new annoucement.\"}";
    }
    if (!announcement.containsKey("motivation")) {
        // This should always exist.
        Response.status(HttpURLConnection.HTTP_BAD_REQUEST).entity("Missing 'motivation' property.").build();
        return "{\"error\":\"Annoucements without 'motivation' are not allowed on this server.\"}";
    }

    //NORMALIZATIONS       
    if (!announcement.containsKey("@context")) {
        // Put in a default, please.
        announcement = new Message().generate(announcement, "@context", CONTEXT);
    }
    
    // add timestamp
    Date time = new Date();
        announcement = new Message().generate(announcement, "published", time.toString());

    try {
        announcement = postMessage(announcement);
    } catch (Exception ex) {
        Logger.getLogger(Message.class.getName()).log(Level.SEVERE, null, ex);
    }
    return announcement.toString();
}
 
开发者ID:CenterForDigitalHumanities,项目名称:inbox,代码行数:45,代码来源:MessagesResource.java

示例9: handle

import javax.json.JsonObject; //导入方法依赖的package包/类
@Override
public Response handle() throws Exception {
  JsonObject payload = getRequest().getPayload();
  JsonObject cookie = payload.getJsonObject("cookie");

  String name = cookie.getString("name", "");
  String value = cookie.getString("value", "");
  String path = cookie.getString("path", "/");
  String domain;
  if (cookie.containsKey("domain")) {
    domain = cookie.getString("domain");
  } else {
    URL url = new URL(getWebDriver().getCurrentUrl());
    domain = url.getHost();
  }
  boolean secure = cookie.getBoolean("secure", false);
  boolean httpOnly = cookie.getBoolean("httpOnly", false);
  Instant expiry =
      cookie.containsKey("expiry")
      ? Instant.ofEpochSecond(cookie.getJsonNumber("expiry").longValueExact())
      : OffsetDateTime.now(ZoneOffset.UTC).plusYears(20).toInstant();

  getWebDriver().addCookie(name, value, path, domain, secure, httpOnly, expiry);
  Response res = new Response();
  res.setSessionId(getSession().getSessionId());
  res.setStatus(0);
  return res;
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:29,代码来源:AddCookieHandler.java

示例10: getDatasourceId

import javax.json.JsonObject; //导入方法依赖的package包/类
public OptionalInt getDatasourceId(String name) throws IOException {
    try {
        String json = get(new URL(uri + "/api/datasources/id/" + name));
        JsonReader jsonReader = Json.createReader(new StringReader(json));
        JsonObject jsonObject = jsonReader.readObject();
        if (jsonObject.containsKey("id")) {
            return OptionalInt.of(jsonObject.getInt("id"));
        }
    } catch (ResponseErrorException e) {
        if (e.getResponseCode() != 404) {
            throw e;
        }
    }
    return OptionalInt.empty();
}
 
开发者ID:jotak,项目名称:hawkular-java-toolbox,代码行数:16,代码来源:GrafanaConnection.java

示例11: isEqual

import javax.json.JsonObject; //导入方法依赖的package包/类
public boolean isEqual(JsonObject other) {
  // The user returned from the microservice won't have a password in it, so
  // don't compare that field.
  if (other.containsKey(JSON_KEY_USER_PASSWORD)) {
    throw new IllegalStateException("User object should not contain a password");
  }

  return (id.equals(other.getString(JSON_KEY_USER_ID))
      && firstName.equals(other.getString(JSON_KEY_USER_FIRST_NAME))
      && lastName.equals(other.getString(JSON_KEY_USER_LAST_NAME))
      && userName.equals(other.getString(JSON_KEY_USER_NAME))
      && twitterHandle.equals(other.getString(JSON_KEY_USER_TWITTER_HANDLE))
      && wishListLink.equals(other.getString(JSON_KEY_USER_WISH_LIST_LINK)));
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:15,代码来源:User.java

示例12: getString

import javax.json.JsonObject; //导入方法依赖的package包/类
public static String getString(String key, JsonObject json) {
   	String result = null;
	if (json.containsKey(key)) {
		JsonString value = json.getJsonString(key);
		if (value != null) {
			result = value.getString();
		}
	}
	return result;
}
 
开发者ID:samolisov,项目名称:bluemix-liberty-microprofile-demo,代码行数:11,代码来源:JsonUtil.java

示例13: parseAddress

import javax.json.JsonObject; //导入方法依赖的package包/类
@Override
public Address parseAddress(JsonObject json) {
    JsonArray result = json.getJsonArray("results");
    if (result != null) {
        JsonArray locations = result.getJsonObject(0).getJsonArray("locations");
        if (locations != null) {
            JsonObject location = locations.getJsonObject(0);

            Address address = new Address();

            if (location.containsKey("street")) {
                address.setStreet(location.getString("street"));
            }
            if (location.containsKey("adminArea5")) {
                address.setSettlement(location.getString("adminArea5"));
            }
            if (location.containsKey("adminArea4")) {
                address.setDistrict(location.getString("adminArea4"));
            }
            if (location.containsKey("adminArea3")) {
                address.setState(location.getString("adminArea3"));
            }
            if (location.containsKey("adminArea1")) {
                address.setCountry(location.getString("adminArea1").toUpperCase());
            }
            if (location.containsKey("postalCode")) {
                address.setPostcode(location.getString("postalCode"));
            }

            return address;
        }
    }
    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:35,代码来源:MapQuestGeocoder.java

示例14: getTime

import javax.json.JsonObject; //导入方法依赖的package包/类
public static LocalTime getTime(String key, JsonObject json) {
	LocalTime result = null;
	if (json.containsKey(key)) {
		JsonString value = json.getJsonString(key);
		if (value != null) {
			result = time(value.getString());
		}
	}
	return result;
}
 
开发者ID:samolisov,项目名称:bluemix-liberty-microprofile-demo,代码行数:11,代码来源:JsonUtil.java

示例15: getDuration

import javax.json.JsonObject; //导入方法依赖的package包/类
public static Duration getDuration(String key, JsonObject json) {
	Duration result = null;
	if (json.containsKey(key)) {
		JsonNumber value = json.getJsonNumber(key);
		if (value != null) {
			result = duration(value.intValueExact());
		}
	}
	return result;
}
 
开发者ID:samolisov,项目名称:bluemix-liberty-microprofile-demo,代码行数:11,代码来源:JsonUtil.java


注:本文中的javax.json.JsonObject.containsKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。