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


Java Json类代码示例

本文整理汇总了Java中play.libs.Json的典型用法代码示例。如果您正苦于以下问题:Java Json类的具体用法?Java Json怎么用?Java Json使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testCreateNoteWithInvalidRequestData

import play.libs.Json; //导入依赖的package包/类
@Test
public void testCreateNoteWithInvalidRequestData() {
  PowerMockito.mockStatic(RequestInterceptor.class);
  when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
  Map<String , Object> requestMap = new HashMap<>();
  Map<String , Object> innerMap = new HashMap<>();
  innerMap.put(JsonKey.USER_ID , "");
  innerMap.put(JsonKey.COURSE_ID , "org123");
  innerMap.put(JsonKey.NOTE , "");
  innerMap.put(JsonKey.TITLE , "org123");
  requestMap.put(JsonKey.REQUEST , innerMap);
  String data = mapToJson(requestMap);

  JsonNode json = Json.parse(data);
  RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/note/create").method("POST");
  req.headers(headerMap);
  Result result = route(req);
  assertEquals(400, result.status());
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-service,代码行数:20,代码来源:NotesControllerTest.java

示例2: updateDatasetSecurity

import play.libs.Json; //导入依赖的package包/类
public static Promise<Result> updateDatasetSecurity(int datasetId) {
    String username = session("user");
    if (StringUtils.isNotBlank(username)) {
        final String queryUrl = BACKEND_URL + DATASET_SECURITY_PATH;

        final JsonNode queryNode = Json.newObject()
            .put("datasetId", datasetId)
            .set("securitySpecification", request().body().asJson());

        return WS.url(queryUrl)
            .setRequestTimeout(1000)
            .post(queryNode)
            .map(response ->
                ok(response.asJson())
            );
    } else {
        final JsonNode result = Json.newObject()
            .put("status", "failed")
            .put("error", "true")
            .put("msg", "Unauthorized User.");

        return Promise.promise(() -> ok(result));
    }
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:25,代码来源:Dataset.java

示例3: favorite

import play.libs.Json; //导入依赖的package包/类
public static boolean favorite(int id, String user)
{
	ObjectNode resultNode = Json.newObject();
	boolean result = false;
	Integer userId = UserDAO.getUserIDByUserName(user);

	if (userId != null && userId !=0)
	{
		int row = getJdbcTemplate().update(FAVORITE_A_DATASET, userId, id);
		if (row > 0)
		{
			result = true;
		}
	}
	return result;
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:17,代码来源:DatasetsDAO.java

示例4: testDisableRoom

import play.libs.Json; //导入依赖的package包/类
@Test
@RunAsAdmin
public void testDisableRoom() throws Exception {

    // Setup
    ExamRoom room = Ebean.find(ExamRoom.class, 1L);
    assertThat(room.getState()).isNotEqualTo(ExamRoom.State.INACTIVE.toString());

    // Execute
    Result result = request(Helpers.DELETE, "/app/rooms/" + 1, null);
    assertThat(result.status()).isEqualTo(200);

    // Verify (both response and database)
    JsonNode node = Json.parse(contentAsString(result));
    ExamRoom deserialized = deserialize(ExamRoom.class, node);
    assertThat(deserialized.getState()).isEqualTo(ExamRoom.State.INACTIVE.toString());

    room = Ebean.find(ExamRoom.class, 1L);
    assertThat(room.getState()).isEqualTo(ExamRoom.State.INACTIVE.toString());
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:21,代码来源:RoomControllerTest.java

示例5: assignApp

import play.libs.Json; //导入依赖的package包/类
private static void assignApp(LineageNodeLite node) {
    List<Map<String, Object>> rows = null;
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("urn", node.urn);
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(getJdbcTemplate().getDataSource());

    rows = namedParameterJdbcTemplate.queryForList(GET_DATA_ATTR, parameters);

    for (Map<String, Object> row : rows) {
        // node only knows id, level, and urn, assign all other attributes

        // stored in dict_dataset, so has those fields
        JsonNode prop = Json.parse((String) row.get("properties"));

        // properties is a JsonNode, extract what we want out of it
        node.description = (prop.has("description")) ? prop.get("description").asText() : "null";
        node.app_code = (prop.has("app_code")) ? prop.get("app_code").asText() : "null";

        // check wh_property for a user specified color, use some generic defaults if nothing found
        //node.color = getColor(node.urn, node.node_type);

        // set things to show up in tooltip
        node._sort_list.add("app_code");
        node._sort_list.add("description");
    }
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:27,代码来源:LineageDAOLite.java

示例6: testDisabledRoomNotVisibleToStudent

import play.libs.Json; //导入依赖的package包/类
@Test
@RunAsStudent
public void testDisabledRoomNotVisibleToStudent() throws Exception {

    // Setup
    ExamRoom room = Ebean.find(ExamRoom.class, 1L);
    room.setState(ExamRoom.State.INACTIVE.toString());
    room.update();

    // Execute
    Result result = get("/app/rooms");
    assertThat(result.status()).isEqualTo(200);

    // Verify
    JsonNode node = Json.parse(contentAsString(result));
    assertPathsDoNotExist(node, String.format("$.[?(@.id == %s)]", room.getId()));
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:18,代码来源:RoomControllerTest.java

示例7: testcreateGeoLocation

import play.libs.Json; //导入依赖的package包/类
@Test
public void testcreateGeoLocation() {
  PowerMockito.mockStatic(RequestInterceptor.class);
  when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
  Map<String , Object> requestMap = new HashMap<>();
  Map<String , Object> innerMap = new HashMap<>();
  innerMap.put(JsonKey.ROOT_ORG_ID , "org123");
  requestMap.put(JsonKey.REQUEST , innerMap);
  String data = mapToJson(requestMap);

  JsonNode json = Json.parse(data);
  RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/location/create").method("POST");
  req.headers(headerMap);
  Result result = route(req);
  assertEquals(200, result.status());
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-service,代码行数:17,代码来源:GeoLocationControllerTest.java

示例8: doPost

import play.libs.Json; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
    ObjectNode reservation = Json.newObject();
    DateTime soon = DateTime.now().plusHours(1);
    reservation.put("start", ISODateTimeFormat.dateTime().print(soon));
    reservation.put("end", ISODateTimeFormat.dateTime().print(soon.plusHours(1)));
    reservation.put("id", RESERVATION_REF);
    reservation.put("externalUserRef", "[email protected]");
    ObjectNode machine = Json.newObject();
    machine.put("name", "Machine 1");
    ObjectNode room = Json.newObject();
    room.put("name", "Room 1");
    room.put("roomCode", "R1");
    room.put("localTimezone", "Europe/Helsinki");
    room.put("roomInstructionEN", "information in English here");
    room.put("buildingName", "B1");
    ObjectNode addressNode = Json.newObject();
    addressNode.put("city", "Paris");
    addressNode.put("street", "123 Rue Monet");
    addressNode.put("zip", "1684");
    room.set("mailAddress", addressNode);
    machine.set("room", room);
    reservation.set("machine", machine);

    RemoteServerHelper.writeJsonResponse(response, reservation, HttpServletResponse.SC_CREATED);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:27,代码来源:ExternalCalendarInterfaceTest.java

示例9: asJson

import play.libs.Json; //导入依赖的package包/类
private ArrayNode asJson(List<User> users) {
    ArrayNode array = JsonNodeFactory.instance.arrayNode();
    for (User u : users) {
        String name = String.format("%s %s", u.getFirstName(), u.getLastName());
        if (u.getUserIdentifier() != null) {
            name += String.format(" (%s)", u.getUserIdentifier());
        }
        ObjectNode part = Json.newObject();
        part.put("id", u.getId());
        part.put("firstName", u.getFirstName());
        part.put("lastName", u.getLastName());
        part.put("userIdentifier", u.getUserIdentifier());
        part.put("name", name);
        array.add(part);
    }
    return array;
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:18,代码来源:ReservationController.java

示例10: testgetAssessment

import play.libs.Json; //导入依赖的package包/类
@Test
public void testgetAssessment() {
  PowerMockito.mockStatic(RequestInterceptor.class);
  when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
  Map<String , Object> requestMap = new HashMap<>();
  Map<String , Object> innerMap = new HashMap<>();
  innerMap.put("courseId" , "course-123");
  requestMap.put(JsonKey.REQUEST , innerMap);
  String data = mapToJson(requestMap);

  JsonNode json = Json.parse(data);
  RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/assessment/result/read").method("POST");
  req.headers(headerMap);
  Result result = route(req);
  assertEquals(200, result.status());
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-service,代码行数:17,代码来源:AssessmentControllerTest.java

示例11: testlogout

import play.libs.Json; //导入依赖的package包/类
@Test
public void testlogout() {
  PowerMockito.mockStatic(RequestInterceptor.class);
  when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
  Map<String , Object> requestMap = new HashMap<>();
  Map<String , Object> innerMap = new HashMap<>();
  innerMap.put(JsonKey.USERNAME , "userName");

  requestMap.put(JsonKey.REQUEST , innerMap);
  String data = mapToJson(requestMap);

  JsonNode json = Json.parse(data);
  RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/user/logout").method("POST");
  req.headers(headerMap);
  Result result = route(req);
  assertEquals(200, result.status());
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-service,代码行数:18,代码来源:UserControllerTest.java

示例12: testcreateTanentPreference

import play.libs.Json; //导入依赖的package包/类
@Test
public void testcreateTanentPreference() {
  PowerMockito.mockStatic(RequestInterceptor.class);
  when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
  Map<String , Object> requestMap = new HashMap<>();
  Map<String , Object> innerMap = new HashMap<>();
  innerMap.put(JsonKey.ROLE , "admin");
  innerMap.put(JsonKey.DATA , "displayPage");
  innerMap.put(JsonKey.ROOT_ORG_ID , "rootOrg001");
  requestMap.put(JsonKey.REQUEST , innerMap);
  String data = mapToJson(requestMap);

  JsonNode json = Json.parse(data);
  RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/org/tc/create").method("POST");
  req.headers(headerMap);
  Result result = route(req);
  assertEquals(200, result.status());
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-service,代码行数:19,代码来源:TenantPreferenceControllerTest.java

示例13: getAtTimeWindow

import play.libs.Json; //导入依赖的package包/类
public static Result getAtTimeWindow(String type, long time, long window) throws SQLException {
  ObjectNode resultJson = Json.newObject();
  try {
    if (type == null) {
      ContrUtil.failure(resultJson, "no type provided");
      Logger.error("no type provided");
    } else {
      long firsttime = time - window;
      long secondtime = time + window;
      resultJson = DatasetDao.getLatestBetween(type, firsttime, secondtime);
    }
  } catch (SQLException e) {
    ContrUtil.failure(resultJson, e.getMessage());
    Logger.error(e.getMessage());
  }
  return ok(resultJson);
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:18,代码来源:DatasetController.java

示例14: getDatasetByID

import play.libs.Json; //导入依赖的package包/类
public static Result getDatasetByID(int id)
{
    String username = session("user");
    models.Dataset dataset = DatasetsDAO.getDatasetByID(id, username);

    ObjectNode result = Json.newObject();

    if (dataset != null)
    {
        result.put("status", "ok");
        result.set("dataset", Json.toJson(dataset));
    }
    else
    {
        result.put("status", "error");
        result.put("message", "record not found");
    }

    return ok(result);
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:21,代码来源:Dataset.java

示例15: getDatasetColumnByID

import play.libs.Json; //导入依赖的package包/类
public static Result getDatasetColumnByID(int datasetId, int columnId)
{
    List<DatasetColumn> datasetColumnList = DatasetsDAO.getDatasetColumnByID(datasetId, columnId);

    ObjectNode result = Json.newObject();

    if (datasetColumnList != null && datasetColumnList.size() > 0)
    {
        result.put("status", "ok");
        result.set("columns", Json.toJson(datasetColumnList));
    }
    else
    {
        result.put("status", "error");
        result.put("message", "record not found");
    }

    return ok(result);
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:20,代码来源:Dataset.java


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