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


Java Json.fromJson方法代码示例

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


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

示例1: patch

import play.libs.Json; //导入方法依赖的package包/类
/**
 * @return One alert.
 */
public Result patch(String id) throws Exception {

    AlarmStatus alarm = Json.fromJson(request().body().asJson(), AlarmStatus.class);

    // validate input
    if (!(alarm.status.equalsIgnoreCase("open") ||
          alarm.status.equalsIgnoreCase("closed") ||
          alarm.status.equalsIgnoreCase("acknowledged"))) {

        return badRequest(
            "Status must be `open`, acknowledged`, or `closed`. " +
                "Value provided: " + alarm.status);
    }

    return ok(toJson(new AlarmApiModel(this.alarms.update(id, alarm.status))));
}
 
开发者ID:Azure,项目名称:device-telemetry-java,代码行数:20,代码来源:AlarmsController.java

示例2: post

import play.libs.Json; //导入方法依赖的package包/类
/**
 * create a new item
 *
 * @return result
 */
public Result post(String collectionId) throws Exception {
    String key = keyGenerator.generate();
    ensureValidId(collectionId, key);
    JsonNode jsonBody = request().body().asJson();
    ValueServiceModel inputModel = Json.fromJson(jsonBody, ValueServiceModel.class);
    ValueServiceModel result = this.container.create(collectionId, key, inputModel);
    return ok(toJson(new ValueApiModel(result)));
}
 
开发者ID:Azure,项目名称:pcs-storage-adapter-java,代码行数:14,代码来源:ValuesController.java

示例3: put

import play.libs.Json; //导入方法依赖的package包/类
/**
 * create or update an item
 *
 * @return result
 */
public Result put(String collectionId, String key) throws Exception {
    ensureValidId(collectionId, key);
    JsonNode jsonBody = request().body().asJson();
    ValueServiceModel inputModel = Json.fromJson(jsonBody, ValueServiceModel.class);
    ValueServiceModel result = (inputModel.ETag == null) ?
            this.container.create(collectionId, key, inputModel) :
            this.container.upsert(collectionId, key, inputModel);
    return ok(toJson(new ValueApiModel(result)));
}
 
开发者ID:Azure,项目名称:pcs-storage-adapter-java,代码行数:15,代码来源:ValuesController.java

示例4: getTest

import play.libs.Json; //导入方法依赖的package包/类
@Test(timeout = 100000)
public void getTest() throws Exception {
    String testKey = keyGenerator.generate();
    String testValue = keyGenerator.generate();
    ValueServiceModel model = new ValueServiceModel(testKey, testValue);
    Mockito.when(mockStorage.get(Mockito.any(String.class), Mockito.any(String.class)))
            .thenReturn(model);
    String resultJson = TestUtils.getString(controller.get(keyGenerator.generate(), keyGenerator.generate()));
    ValueServiceModel result = Json.fromJson(Json.parse(resultJson), ValueServiceModel.class);
    assertEquals(result.Data, testValue);
}
 
开发者ID:Azure,项目名称:pcs-storage-adapter-java,代码行数:12,代码来源:ValuesControllerTest.java

示例5: createTest

import play.libs.Json; //导入方法依赖的package包/类
@Test(timeout = 100000)
public void createTest() throws Exception {
    String testValue = keyGenerator.generate();
    String testKey = keyGenerator.generate();
    ValueServiceModel model = new ValueServiceModel(testKey, testValue);
    Mockito.when(mockStorage.create(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(ValueServiceModel.class)))
            .thenReturn(model);
    TestUtils.setRequest(String.format("{\"Data\":\"%s\"}", keyGenerator.generate(), keyGenerator.generate()));
    String resultJson = TestUtils.getString(controller.put(keyGenerator.generate(), keyGenerator.generate()));
    ValueServiceModel result = Json.fromJson(Json.parse(resultJson), ValueServiceModel.class);
    assertEquals(result.Data, testValue);
}
 
开发者ID:Azure,项目名称:pcs-storage-adapter-java,代码行数:13,代码来源:ValuesControllerTest.java

示例6: updateTest

import play.libs.Json; //导入方法依赖的package包/类
@Test(timeout = 100000)
public void updateTest() throws Exception {
    String testKey = keyGenerator.generate();
    String testValue = keyGenerator.generate();
    ValueServiceModel model = new ValueServiceModel(testKey, testValue);
    Mockito.when(mockStorage.upsert(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(ValueServiceModel.class)))
            .thenReturn(model);
    TestUtils.setRequest(String.format("{\"ETag\":\"%s\",\"Data\":\"%s\"}", keyGenerator.generate(), keyGenerator.generate()));
    String resultJson = TestUtils.getString(controller.put(keyGenerator.generate(), keyGenerator.generate()));
    ValueServiceModel result = Json.fromJson(Json.parse(resultJson), ValueServiceModel.class);
    assertEquals(result.Data, testValue);
}
 
开发者ID:Azure,项目名称:pcs-storage-adapter-java,代码行数:13,代码来源:ValuesControllerTest.java

示例7: mapRequest

import play.libs.Json; //导入方法依赖的package包/类
/**
 * Method to map request
 * 
 * @param requestData JsonNode
 * @param obj Class<T>
 * @exception RuntimeException
 * @return <T>
 */
public static <T> Object mapRequest(JsonNode requestData, Class<T> obj) throws RuntimeException {

  try {
    return Json.fromJson(requestData, obj);
  } catch (Exception e) {
    ProjectLogger.log("ControllerRequestMapper error : " + e.getMessage(), e);
    ProjectLogger.log("Request Data" + requestData.toString(),
        LoggerEnum.INFO.name());
    throw new ProjectCommonException(ResponseCode.invalidData.getErrorCode(),
        ResponseCode.invalidData.getErrorMessage(),
        ResponseCode.CLIENT_ERROR.getResponseCode());
  }
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-service,代码行数:22,代码来源:RequestMapper.java


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