當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。