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


Java JsonPath.parse方法代码示例

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


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

示例1: validate_apiV1NotesNoteIdGet_withValidArchivedIdAndUserId_ReturnArchivedNote

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Test
public void validate_apiV1NotesNoteIdGet_withValidArchivedIdAndUserId_ReturnArchivedNote() throws Exception {
	// given:
		MockMvcRequestSpecification request = given()
				.header("userId", "1");

	// when:
		ResponseOptions<?> response = given().spec(request)
				.get("/api/v1/notes/aexistingNoteId");

	// then:
		assertThat(response.statusCode()).isEqualTo(200);
		assertThat(response.header("Content-Type")).matches("application/json.*");
	// and:
		DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
		assertThatJson(parsedJson).field("title").isEqualTo("a1latest");
		assertThatJson(parsedJson).field("id").matches(".+");
		assertThatJson(parsedJson).field("lastEdit").matches(".+");
		assertThatJson(parsedJson).field("archived").isEqualTo(true);
		assertThatJson(parsedJson).field("content").matches(".+");
}
 
开发者ID:daflockinger,项目名称:poppynotes,代码行数:22,代码来源:ApiContractTest.java

示例2: testNavDate

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Test
public void testNavDate() throws IOException {
  OffsetDateTime navDate = OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
  Manifest manifest = new Manifest("http://some.uri", "A label for the Manifest");
  manifest.setNavDate(navDate);
  String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(manifest);
  DocumentContext ctx = JsonPath.parse(json);
  JsonPathAssert.assertThat(ctx).jsonPathAsString("navDate").isEqualTo("1970-01-01T00:00:00Z");
  assertThat(mapper.readValue(json, Manifest.class).getNavDate()).isEqualTo(manifest.getNavDate());

  Collection coll = new Collection("http://some.uri", "A label for the Collection");
  coll.setNavDate(navDate);
  json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(coll);
  ctx = JsonPath.parse(json);
  JsonPathAssert.assertThat(ctx).jsonPathAsString("navDate").isEqualTo("1970-01-01T00:00:00Z");
  assertThat(mapper.readValue(json, Collection.class).getNavDate()).isEqualTo(navDate);
}
 
开发者ID:dbmdz,项目名称:iiif-apis,代码行数:18,代码来源:JsonMappingTest.java

示例3: validate_apiV1NotesGet_withCorrectRequestPaginatedShorArchived_ReturnArchivedCorrect

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Test
public void validate_apiV1NotesGet_withCorrectRequestPaginatedShorArchived_ReturnArchivedCorrect() throws Exception {
	// given:
		MockMvcRequestSpecification request = given()
				.header("userId", "1");

	// when:
		ResponseOptions<?> response = given().spec(request)
				.get("/api/v1/notes?page=1&items=2&showArchived=true");

	// then:
		assertThat(response.statusCode()).isEqualTo(200);
		assertThat(response.header("Content-Type")).matches("application/json.*");
	// and:
		DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
		assertThatJson(parsedJson).array().contains("pinned").isEqualTo(true);
		assertThatJson(parsedJson).array().contains("lastEdit").matches(".+");
		assertThatJson(parsedJson).array().contains("archived").isNull();
		assertThatJson(parsedJson).array().contains("pinned").isEqualTo(false);
		assertThatJson(parsedJson).array().contains("id").matches(".+");
		assertThatJson(parsedJson).array().contains("partContent").matches(".+");
		assertThatJson(parsedJson).array().contains("title").isEqualTo("a3-pinned-third");
		assertThatJson(parsedJson).array().contains("title").isEqualTo("a1latest");
}
 
开发者ID:daflockinger,项目名称:poppynotes,代码行数:25,代码来源:ApiContractTest.java

示例4: convert

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
public AttributeRequest convert(String topic, MqttMessage msg) {
    deviceNameTopicPattern = checkAndCompile(deviceNameTopicPattern, deviceNameTopicExpression);
    attributeKeyTopicPattern = checkAndCompile(attributeKeyTopicPattern, attributeKeyTopicExpression);
    requestIdTopicPattern = checkAndCompile(requestIdTopicPattern, requestIdTopicExpression);

    String data = new String(msg.getPayload(), StandardCharsets.UTF_8);
    DocumentContext document = JsonPath.parse(data);

    AttributeRequest.AttributeRequestBuilder builder = AttributeRequest.builder();
    builder.deviceName(eval(topic, deviceNameTopicPattern, document, deviceNameJsonExpression));
    builder.attributeKey(eval(topic, attributeKeyTopicPattern, document, attributeKeyJsonExpression));
    builder.requestId(Integer.parseInt(eval(topic, requestIdTopicPattern, document, requestIdJsonExpression)));

    builder.clientScope(this.isClientScope());
    builder.topicExpression(this.getResponseTopicExpression());
    builder.valueExpression(this.getValueExpression());
    return builder.build();
}
 
开发者ID:thingsboard,项目名称:thingsboard-gateway,代码行数:19,代码来源:AttributeRequestsMapping.java

示例5: validate_apiV1NotesPost_withMissingTitle_ReturnBadRequest

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Test
public void validate_apiV1NotesPost_withMissingTitle_ReturnBadRequest() throws Exception {
	// given:
		MockMvcRequestSpecification request = given()
				.header("userId", "1")
				.header("Content-Type", "application/json")
				.body("{\"pinned\":true,\"lastEdit\":\"2012-12-12T12:12:12Z\",\"userId\":1,\"archived\":false,\"content\":\"some text\",\"initVector\":\"aldk8796\"}");

	// when:
		ResponseOptions<?> response = given().spec(request)
				.post("/api/v1/notes");

	// then:
		assertThat(response.statusCode()).isEqualTo(400);
		assertThat(response.header("Content-Type")).matches("application/json.*");
	// and:
		DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
		assertThatJson(parsedJson).field("code").isNull();
		assertThatJson(parsedJson).field("message").matches(".+");
}
 
开发者ID:daflockinger,项目名称:poppynotes,代码行数:21,代码来源:ApiContractTest.java

示例6: validate_apiV1NotesPut_withNonExistingNote_ReturnNotFound

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Test
public void validate_apiV1NotesPut_withNonExistingNote_ReturnNotFound() throws Exception {
	// given:
		MockMvcRequestSpecification request = given()
				.header("userId", "1")
				.header("Content-Type", "application/json")
				.body("{\"id\":\"nonExista\",\"title\":\"new note\",\"lastEdit\":\"2012-12-12T12:12:12Z\",\"pinned\":false,\"archived\":false,\"content\":\"some text\",\"userId\":1,\"initVector\":\"aldk8796\"}");

	// when:
		ResponseOptions<?> response = given().spec(request)
				.put("/api/v1/notes");

	// then:
		assertThat(response.statusCode()).isEqualTo(404);
		assertThat(response.header("Content-Type")).matches("application/json.*");
	// and:
		DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
		assertThatJson(parsedJson).field("code").isNull();
		assertThatJson(parsedJson).field("message").matches(".+");
}
 
开发者ID:daflockinger,项目名称:poppynotes,代码行数:21,代码来源:ApiContractTest.java

示例7: validate_apiV1NotesPut_withMissingPinned_ReturnBadRequest

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Test
public void validate_apiV1NotesPut_withMissingPinned_ReturnBadRequest() throws Exception {
	// given:
		MockMvcRequestSpecification request = given()
				.header("userId", "1")
				.header("Content-Type", "application/json")
				.body("{\"title\":\"new note\",\"lastEdit\":\"2012-12-12T12:12:12Z\",\"userId\":1,\"archived\":false,\"content\":\"some text\",\"initVector\":\"aldk8796\"}");

	// when:
		ResponseOptions<?> response = given().spec(request)
				.post("/api/v1/notes");

	// then:
		assertThat(response.statusCode()).isEqualTo(400);
		assertThat(response.header("Content-Type")).matches("application/json.*");
	// and:
		DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
		assertThatJson(parsedJson).field("code").isNull();
		assertThatJson(parsedJson).field("message").matches(".+");
}
 
开发者ID:daflockinger,项目名称:poppynotes,代码行数:21,代码来源:ApiContractTest.java

示例8: validate_apiV1NotesPost_withMissingLastEdit_ReturnBadRequest

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Test
public void validate_apiV1NotesPost_withMissingLastEdit_ReturnBadRequest() throws Exception {
	// given:
		MockMvcRequestSpecification request = given()
				.header("userId", "1")
				.header("Content-Type", "application/json")
				.body("{\"title\":\"new note\",\"pinned\":true,\"userId\":1,\"archived\":false,\"content\":\"some text\",\"initVector\":\"aldk8796\"}");

	// when:
		ResponseOptions<?> response = given().spec(request)
				.post("/api/v1/notes");

	// then:
		assertThat(response.statusCode()).isEqualTo(400);
		assertThat(response.header("Content-Type")).matches("application/json.*");
	// and:
		DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
		assertThatJson(parsedJson).field("code").isNull();
		assertThatJson(parsedJson).field("message").matches(".+");
}
 
开发者ID:daflockinger,项目名称:poppynotes,代码行数:21,代码来源:ApiContractTest.java

示例9: toJsonDoc

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
public static DocumentContext toJsonDoc(ScriptValue sv, ScriptContext context) {
    if (sv.getType() == JSON) { // optimize
        return (DocumentContext) sv.getValue();
    } else if (sv.isListLike()) {
        return JsonPath.parse(sv.getAsList());
    } else if (sv.isMapLike()) {
        return JsonPath.parse(sv.getAsMap());
    } else if (sv.isUnknownType()) { // POJO
        return JsonUtils.toJsonDoc(sv.getValue());
    } else if (sv.isStringOrStream()) {
        ScriptValue temp = evalKarateExpression(sv.getAsString(), context);
        if (temp.getType() != JSON) {
            throw new RuntimeException("cannot convert, not a json string: " + sv);
        }
        return temp.getValue(DocumentContext.class);
    } else {
        throw new RuntimeException("cannot convert to json: " + sv);
    }
}
 
开发者ID:intuit,项目名称:karate,代码行数:20,代码来源:Script.java

示例10: validate_apiV1NotesGet_withCorrectRequestNonPaginated_ReturnDefaultCorrect

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Test
public void validate_apiV1NotesGet_withCorrectRequestNonPaginated_ReturnDefaultCorrect() throws Exception {
	// given:
		MockMvcRequestSpecification request = given()
				.header("userId", "1");

	// when:
		ResponseOptions<?> response = given().spec(request)
				.get("/api/v1/notes");

	// then:
		assertThat(response.statusCode()).isEqualTo(200);
		assertThat(response.header("Content-Type")).matches("application/json.*");
	// and:
		DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
		assertThatJson(parsedJson).array().contains("pinned").isEqualTo(true);
		assertThatJson(parsedJson).array().contains("lastEdit").matches(".+");
		assertThatJson(parsedJson).array().contains("archived").isNull();
		assertThatJson(parsedJson).array().contains("pinned").isEqualTo(false);
		assertThatJson(parsedJson).array().contains("title").isEqualTo("2-pinned-second");
		assertThatJson(parsedJson).array().contains("title").isEqualTo("1latest");
		assertThatJson(parsedJson).array().contains("id").matches(".+");
		assertThatJson(parsedJson).array().contains("partContent").matches(".+");
		assertThatJson(parsedJson).array().contains("title").isEqualTo("3-pinned-third");
		assertThatJson(parsedJson).array().contains("title").isEqualTo("2second");
}
 
开发者ID:daflockinger,项目名称:poppynotes,代码行数:27,代码来源:ApiContractTest.java

示例11: getAsJsonDocument

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
public DocumentContext getAsJsonDocument() {
    switch (type) {
        case JSON:
            return getValue(DocumentContext.class);
        case JS_ARRAY: // happens for json resulting from nashorn
            ScriptObjectMirror som = getValue(ScriptObjectMirror.class);
            return JsonPath.parse(som.values());
        case JS_OBJECT: // is a map-like object, happens for json resulting from nashorn
        case MAP: // this happens because some jsonpath operations result in Map
            Map<String, Object> map = getValue(Map.class);
            return JsonPath.parse(map);
        case LIST: // this also happens because some jsonpath operations result in List
            List list = getValue(List.class);
            return JsonPath.parse(list);
        default:
            throw new RuntimeException("cannot convert to json: " + this);
    }
}
 
开发者ID:intuit,项目名称:karate,代码行数:19,代码来源:ScriptValue.java

示例12: validate_apiV1NotesPut_withMissingTitle_ReturnBadRequest

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Test
public void validate_apiV1NotesPut_withMissingTitle_ReturnBadRequest() throws Exception {
	// given:
		MockMvcRequestSpecification request = given()
				.header("userId", "1")
				.header("Content-Type", "application/json")
				.body("{\"pinned\":true,\"lastEdit\":\"2012-12-12T12:12:12Z\",\"userId\":1,\"archived\":false,\"content\":\"some text\",\"initVector\":\"aldk8796\"}");

	// when:
		ResponseOptions<?> response = given().spec(request)
				.post("/api/v1/notes");

	// then:
		assertThat(response.statusCode()).isEqualTo(400);
		assertThat(response.header("Content-Type")).matches("application/json.*");
	// and:
		DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
		assertThatJson(parsedJson).field("code").isNull();
		assertThatJson(parsedJson).field("message").matches(".+");
}
 
开发者ID:daflockinger,项目名称:poppynotes,代码行数:21,代码来源:ApiContractTest.java

示例13: testJsonChunkByPath

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Test
public void testJsonChunkByPath() {
    String raw = "[{ foo: 'bar' }]";
    DocumentContext doc = JsonUtils.toJsonDoc(raw);
    Map map = doc.read("$[0]");
    DocumentContext foo = JsonPath.parse(map);
    assertEquals("{\"foo\":\"bar\"}", foo.jsonString());
}
 
开发者ID:intuit,项目名称:karate,代码行数:9,代码来源:JsonUtilsTest.java

示例14: parse

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
private List<DeviceData> parse(String topic, List<String> srcList) {
    List<DeviceData> result = new ArrayList<>(srcList.size());
    for (String src : srcList) {
        DocumentContext document = JsonPath.parse(src);
        long ts = System.currentTimeMillis();
        String deviceName;
        String deviceType = null;
        if (!StringUtils.isEmpty(deviceNameTopicExpression)) {
            deviceName = evalDeviceName(topic);
        } else {
            deviceName = eval(document, deviceNameJsonExpression);
        }
        if (!StringUtils.isEmpty(deviceTypeTopicExpression)) {
            deviceType = evalDeviceType(topic);
        } else if (!StringUtils.isEmpty(deviceTypeJsonExpression)) {
            deviceType = eval(document, deviceTypeJsonExpression);
        }

        if (!StringUtils.isEmpty(deviceName)) {
            List<KvEntry> attrData = getKvEntries(document, attributes);
            List<TsKvEntry> tsData = getKvEntries(document, timeseries).stream()
                    .map(kv -> new BasicTsKvEntry(ts, kv))
                    .collect(Collectors.toList());
            result.add(new DeviceData(deviceName, deviceType, attrData, tsData, timeout));
        }
    }
    return result;
}
 
开发者ID:osswangxining,项目名称:iot-edge-greengrass,代码行数:29,代码来源:MqttJsonConverter.java

示例15: messageArrived

import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Override
public void messageArrived(String topic, MqttMessage msg) throws Exception {
  try {
    if (!StringUtils.isEmpty(mapping.getDeviceNameTopicExpression())) {
      deviceNameConsumer.accept(eval(topic));
    } else {
      String data = new String(msg.getPayload(), StandardCharsets.UTF_8);
      DocumentContext document = JsonPath.parse(data);
      deviceNameConsumer.accept(eval(document, mapping.getDeviceNameJsonExpression()));
    }
  } catch (Exception e) {
    log.error("Failed to convert msg", e);
  }
}
 
开发者ID:osswangxining,项目名称:iotgateway,代码行数:15,代码来源:MqttDeviceStateChangeMessageListener.java


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