io.restassured.path.json.JsonPath.getObject()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(14.3k)|赞(0)|评价(0)|浏览(166)

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

JsonPath.getObject介绍

[英]Get the result of a Object path expression as a java Object with generic type. E.g. given the following Object document:

{ "store": { 
"book": [ 
{ "category": "reference", 
"author": "Nigel Rees", 
"title": "Sayings of the Century", 
"price": 8.95 
}, 
{ "category": "fiction", 
"author": "Evelyn Waugh", 
"title": "Sword of Honour", 
"price": 12.99 
}, 
{ "category": "fiction", 
"author": "Herman Melville", 
"title": "Moby Dick", 
"isbn": "0-553-21311-3", 
"price": 8.99 
}, 
{ "category": "fiction", 
"author": "J. R. R. Tolkien", 
"title": "The Lord of the Rings", 
"isbn": "0-395-19395-8", 
"price": 22.99 
} 
], 
"bicycle": { 
"color": "red", 
"price": 19.95 
} 
} 
}

And you want to get a book as a Map<String, Object>:

Then

Map<String, Object> book = from(Object).getObject("store.book[2]", new TypeRef<Map<String, Object>>() {});

maps the second book to a Book instance.
[中]将对象路径表达式的结果作为泛型类型的java对象获取。例如,给定以下对象文档:

{ "store": { 
"book": [ 
{ "category": "reference", 
"author": "Nigel Rees", 
"title": "Sayings of the Century", 
"price": 8.95 
}, 
{ "category": "fiction", 
"author": "Evelyn Waugh", 
"title": "Sword of Honour", 
"price": 12.99 
}, 
{ "category": "fiction", 
"author": "Herman Melville", 
"title": "Moby Dick", 
"isbn": "0-553-21311-3", 
"price": 8.99 
}, 
{ "category": "fiction", 
"author": "J. R. R. Tolkien", 
"title": "The Lord of the Rings", 
"isbn": "0-395-19395-8", 
"price": 22.99 
} 
], 
"bicycle": { 
"color": "red", 
"price": 19.95 
} 
} 
}

并且您希望以Map<String, Object>的形式获取一本书:
然后

Map<String, Object> book = from(Object).getObject("store.book[2]", new TypeRef<Map<String, Object>>() {});

将第二本书映射到一个书实例。

代码示例

代码示例来源:origin: rest-assured/rest-assured

return getObject(path, typeRef.getTypeAsClass());

代码示例来源:origin: rest-assured/rest-assured

return getObject(path, typeRef.getTypeAsClass());

代码示例来源:origin: camunda/camunda-bpm-platform

UserOperationLogEntryDto actual = from(json).getObject("[0]", UserOperationLogEntryDto.class);
assertEquals(MockProvider.EXAMPLE_USER_OPERATION_LOG_ID, actual.getId());
assertEquals(MockProvider.EXAMPLE_DEPLOYMENT_ID, actual.getDeploymentId());

代码示例来源:origin: camunda/camunda-bpm-platform

protected void verifyBatchJson(String batchJson) {
 BatchDto batch = JsonPathUtil.from(batchJson).getObject("", BatchDto.class);
 assertNotNull("The returned batch should not be null.", batch);
 assertEquals(MockProvider.EXAMPLE_BATCH_ID, batch.getId());
 assertEquals(MockProvider.EXAMPLE_BATCH_TYPE, batch.getType());
 assertEquals(MockProvider.EXAMPLE_BATCH_TOTAL_JOBS, batch.getTotalJobs());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOBS_PER_SEED, batch.getBatchJobsPerSeed());
 assertEquals(MockProvider.EXAMPLE_INVOCATIONS_PER_BATCH_JOB, batch.getInvocationsPerBatchJob());
 assertEquals(MockProvider.EXAMPLE_SEED_JOB_DEFINITION_ID, batch.getSeedJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_MONITOR_JOB_DEFINITION_ID, batch.getMonitorJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOB_DEFINITION_ID, batch.getBatchJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_TENANT_ID, batch.getTenantId());
}

代码示例来源:origin: camunda/camunda-bpm-platform

protected void verifyBatchJson(String batchJson) {
 BatchDto batch = JsonPathUtil.from(batchJson).getObject("", BatchDto.class);
 assertNotNull("The returned batch should not be null.", batch);
 assertEquals(MockProvider.EXAMPLE_BATCH_ID, batch.getId());
 assertEquals(MockProvider.EXAMPLE_BATCH_TYPE, batch.getType());
 assertEquals(MockProvider.EXAMPLE_BATCH_TOTAL_JOBS, batch.getTotalJobs());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOBS_PER_SEED, batch.getBatchJobsPerSeed());
 assertEquals(MockProvider.EXAMPLE_INVOCATIONS_PER_BATCH_JOB, batch.getInvocationsPerBatchJob());
 assertEquals(MockProvider.EXAMPLE_SEED_JOB_DEFINITION_ID, batch.getSeedJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_MONITOR_JOB_DEFINITION_ID, batch.getMonitorJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOB_DEFINITION_ID, batch.getBatchJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_TENANT_ID, batch.getTenantId());
}

代码示例来源:origin: camunda/camunda-bpm-platform

protected void verifyBatchJson(String batchJson) {
 BatchDto batch = JsonPathUtil.from(batchJson).getObject("", BatchDto.class);
 assertNotNull("The returned batch should not be null.", batch);
 assertEquals(MockProvider.EXAMPLE_BATCH_ID, batch.getId());
 assertEquals(MockProvider.EXAMPLE_BATCH_TYPE, batch.getType());
 assertEquals(MockProvider.EXAMPLE_BATCH_TOTAL_JOBS, batch.getTotalJobs());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOBS_PER_SEED, batch.getBatchJobsPerSeed());
 assertEquals(MockProvider.EXAMPLE_INVOCATIONS_PER_BATCH_JOB, batch.getInvocationsPerBatchJob());
 assertEquals(MockProvider.EXAMPLE_SEED_JOB_DEFINITION_ID, batch.getSeedJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_MONITOR_JOB_DEFINITION_ID, batch.getMonitorJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOB_DEFINITION_ID, batch.getBatchJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_TENANT_ID, batch.getTenantId());
}

代码示例来源:origin: camunda/camunda-bpm-platform

String returnedJobConfiguration = from(content).getString("[0].jobConfiguration");
boolean returnedSuspensionState = from(content).getBoolean("[0].suspended");
Long returnedJobPriority = from(content).getObject("[0].overridingJobPriority", Long.class);

代码示例来源:origin: camunda/camunda-bpm-platform

protected void verifyBatchJson(String batchJson) {
  BatchDto batch = JsonPathUtil.from(batchJson).getObject("", BatchDto.class);
  assertNotNull("The returned batch should not be null.", batch);
  assertEquals(MockProvider.EXAMPLE_BATCH_ID, batch.getId());
  assertEquals(MockProvider.EXAMPLE_BATCH_TYPE, batch.getType());
  assertEquals(MockProvider.EXAMPLE_BATCH_TOTAL_JOBS, batch.getTotalJobs());
  assertEquals(MockProvider.EXAMPLE_BATCH_JOBS_PER_SEED, batch.getBatchJobsPerSeed());
  assertEquals(MockProvider.EXAMPLE_INVOCATIONS_PER_BATCH_JOB, batch.getInvocationsPerBatchJob());
  assertEquals(MockProvider.EXAMPLE_SEED_JOB_DEFINITION_ID, batch.getSeedJobDefinitionId());
  assertEquals(MockProvider.EXAMPLE_MONITOR_JOB_DEFINITION_ID, batch.getMonitorJobDefinitionId());
  assertEquals(MockProvider.EXAMPLE_BATCH_JOB_DEFINITION_ID, batch.getBatchJobDefinitionId());
  assertEquals(MockProvider.EXAMPLE_TENANT_ID, batch.getTenantId());
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

protected void verifyBatchListJson(String batchListJson) {
 List<Object> batches = from(batchListJson).get();
 assertEquals("There should be one batch returned.", 1, batches.size());
 BatchDto batch = from(batchListJson).getObject("[0]", BatchDto.class);
 assertNotNull("The returned batch should not be null.", batch);
 assertEquals(MockProvider.EXAMPLE_BATCH_ID, batch.getId());
 assertEquals(MockProvider.EXAMPLE_BATCH_TYPE, batch.getType());
 assertEquals(MockProvider.EXAMPLE_BATCH_TOTAL_JOBS, batch.getTotalJobs());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOBS_CREATED, batch.getJobsCreated());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOBS_PER_SEED, batch.getBatchJobsPerSeed());
 assertEquals(MockProvider.EXAMPLE_INVOCATIONS_PER_BATCH_JOB, batch.getInvocationsPerBatchJob());
 assertEquals(MockProvider.EXAMPLE_SEED_JOB_DEFINITION_ID, batch.getSeedJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_MONITOR_JOB_DEFINITION_ID, batch.getMonitorJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOB_DEFINITION_ID, batch.getBatchJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_TENANT_ID, batch.getTenantId());
 assertEquals(MockProvider.EXAMPLE_USER_ID, batch.getCreateUserId());
 assertTrue(batch.isSuspended());
}

代码示例来源:origin: camunda/camunda-bpm-platform

protected void verifyBatchJson(String batchJson) {
 BatchDto batch = from(batchJson).getObject("", BatchDto.class);
 assertNotNull("The returned batch should not be null.", batch);
 assertEquals(MockProvider.EXAMPLE_BATCH_ID, batch.getId());
 assertEquals(MockProvider.EXAMPLE_BATCH_TYPE, batch.getType());
 assertEquals(MockProvider.EXAMPLE_BATCH_TOTAL_JOBS, batch.getTotalJobs());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOBS_PER_SEED, batch.getBatchJobsPerSeed());
 assertEquals(MockProvider.EXAMPLE_INVOCATIONS_PER_BATCH_JOB, batch.getInvocationsPerBatchJob());
 assertEquals(MockProvider.EXAMPLE_SEED_JOB_DEFINITION_ID, batch.getSeedJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_MONITOR_JOB_DEFINITION_ID, batch.getMonitorJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOB_DEFINITION_ID, batch.getBatchJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_TENANT_ID, batch.getTenantId());
 assertEquals(MockProvider.EXAMPLE_USER_ID, batch.getCreateUserId());
}

代码示例来源:origin: io.rest-assured/json-path

return getObject(path, typeRef.getTypeAsClass());

代码示例来源:origin: camunda/camunda-bpm-platform

protected void verifyHistoricBatchListJson(String historicBatchListJson) {
 List<Object> batches = from(historicBatchListJson).get();
 assertEquals("There should be one historic batch returned.", 1, batches.size());
 HistoricBatchDto historicBatch = from(historicBatchListJson).getObject("[0]", HistoricBatchDto.class);
 assertNotNull("The returned historic batch should not be null.", historicBatch);
 assertEquals(MockProvider.EXAMPLE_BATCH_ID, historicBatch.getId());
 assertEquals(MockProvider.EXAMPLE_BATCH_TYPE, historicBatch.getType());
 assertEquals(MockProvider.EXAMPLE_BATCH_TOTAL_JOBS, historicBatch.getTotalJobs());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOBS_PER_SEED, historicBatch.getBatchJobsPerSeed());
 assertEquals(MockProvider.EXAMPLE_INVOCATIONS_PER_BATCH_JOB, historicBatch.getInvocationsPerBatchJob());
 assertEquals(MockProvider.EXAMPLE_SEED_JOB_DEFINITION_ID, historicBatch.getSeedJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_MONITOR_JOB_DEFINITION_ID, historicBatch.getMonitorJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOB_DEFINITION_ID, historicBatch.getBatchJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_TENANT_ID, historicBatch.getTenantId());
 assertEquals(MockProvider.EXAMPLE_USER_ID, historicBatch.getCreateUserId());
 assertEquals(DateTimeUtil.parseDate(MockProvider.EXAMPLE_HISTORIC_BATCH_START_TIME), historicBatch.getStartTime());
 assertEquals(DateTimeUtil.parseDate(MockProvider.EXAMPLE_HISTORIC_BATCH_END_TIME), historicBatch.getEndTime());
 assertEquals(DateTimeUtil.parseDate(MockProvider.EXAMPLE_HISTORIC_BATCH_REMOVAL_TIME), historicBatch.getRemovalTime());
}

代码示例来源:origin: camunda/camunda-bpm-platform

protected void verifyBatchStatisticsListJson(String batchStatisticsListJson) {
 List<Object> batches = from(batchStatisticsListJson).get();
 assertEquals("There should be one batch statistics returned.", 1, batches.size());
 BatchStatisticsDto batchStatistics = from(batchStatisticsListJson).getObject("[0]", BatchStatisticsDto.class);
 assertNotNull("The returned batch statistics should not be null.", batchStatistics);
 assertEquals(MockProvider.EXAMPLE_BATCH_ID, batchStatistics.getId());
 assertEquals(MockProvider.EXAMPLE_BATCH_TYPE, batchStatistics.getType());
 assertEquals(MockProvider.EXAMPLE_BATCH_TOTAL_JOBS, batchStatistics.getTotalJobs());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOBS_CREATED, batchStatistics.getJobsCreated());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOBS_PER_SEED, batchStatistics.getBatchJobsPerSeed());
 assertEquals(MockProvider.EXAMPLE_INVOCATIONS_PER_BATCH_JOB, batchStatistics.getInvocationsPerBatchJob());
 assertEquals(MockProvider.EXAMPLE_SEED_JOB_DEFINITION_ID, batchStatistics.getSeedJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_MONITOR_JOB_DEFINITION_ID, batchStatistics.getMonitorJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOB_DEFINITION_ID, batchStatistics.getBatchJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_TENANT_ID, batchStatistics.getTenantId());
 assertEquals(MockProvider.EXAMPLE_USER_ID, batchStatistics.getCreateUserId());
 assertEquals(MockProvider.EXAMPLE_BATCH_REMAINING_JOBS, batchStatistics.getRemainingJobs());
 assertEquals(MockProvider.EXAMPLE_BATCH_COMPLETED_JOBS, batchStatistics.getCompletedJobs());
 assertEquals(MockProvider.EXAMPLE_BATCH_FAILED_JOBS, batchStatistics.getFailedJobs());
 assertTrue(batchStatistics.isSuspended());
}

代码示例来源:origin: camunda/camunda-bpm-platform

protected void verifyHistoricBatchJson(String historicBatchJson) {
 HistoricBatchDto historicBatch = from(historicBatchJson).getObject("", HistoricBatchDto.class);
 assertNotNull("The returned historic batch should not be null.", historicBatch);
 assertEquals(MockProvider.EXAMPLE_BATCH_ID, historicBatch.getId());
 assertEquals(MockProvider.EXAMPLE_BATCH_TYPE, historicBatch.getType());
 assertEquals(MockProvider.EXAMPLE_BATCH_TOTAL_JOBS, historicBatch.getTotalJobs());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOBS_PER_SEED, historicBatch.getBatchJobsPerSeed());
 assertEquals(MockProvider.EXAMPLE_INVOCATIONS_PER_BATCH_JOB, historicBatch.getInvocationsPerBatchJob());
 assertEquals(MockProvider.EXAMPLE_SEED_JOB_DEFINITION_ID, historicBatch.getSeedJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_MONITOR_JOB_DEFINITION_ID, historicBatch.getMonitorJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_BATCH_JOB_DEFINITION_ID, historicBatch.getBatchJobDefinitionId());
 assertEquals(MockProvider.EXAMPLE_TENANT_ID, historicBatch.getTenantId());
 assertEquals(MockProvider.EXAMPLE_USER_ID, historicBatch.getCreateUserId());
 assertEquals(DateTimeUtil.parseDate(MockProvider.EXAMPLE_HISTORIC_BATCH_START_TIME), historicBatch.getStartTime());
 assertEquals(DateTimeUtil.parseDate(MockProvider.EXAMPLE_HISTORIC_BATCH_END_TIME), historicBatch.getEndTime());
 assertEquals(DateTimeUtil.parseDate(MockProvider.EXAMPLE_HISTORIC_BATCH_REMOVAL_TIME), historicBatch.getRemovalTime());
}

相关文章