You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.3 KiB
66 lines
2.3 KiB
14 years ago
|
package com.jayway.jsonpath;
|
||
|
|
||
|
import org.junit.Test;
|
||
|
|
||
|
import java.util.Map;
|
||
|
|
||
|
/**
|
||
|
* Created by IntelliJ IDEA.
|
||
|
* User: kallestenflo
|
||
|
* Date: 11/8/11
|
||
|
* Time: 7:52 PM
|
||
|
*/
|
||
14 years ago
|
public class JsonModelTest {
|
||
14 years ago
|
|
||
|
public final static String DOCUMENT =
|
||
|
"{ \"store\": {\n" +
|
||
|
" \"book\": [ \n" +
|
||
|
" { \"category\": \"reference\",\n" +
|
||
|
" \"author\": \"Nigel Rees\",\n" +
|
||
|
" \"title\": \"Sayings of the Century\",\n" +
|
||
|
" \"price\": 8.95\n" +
|
||
|
" },\n" +
|
||
|
" { \"category\": \"fiction\",\n" +
|
||
|
" \"author\": \"Evelyn Waugh\",\n" +
|
||
|
" \"title\": \"Sword of Honour\",\n" +
|
||
|
" \"price\": 12.99\n" +
|
||
|
" },\n" +
|
||
|
" { \"category\": \"fiction\",\n" +
|
||
|
" \"author\": \"Herman Melville\",\n" +
|
||
|
" \"title\": \"Moby Dick\",\n" +
|
||
|
" \"isbn\": \"0-553-21311-3\",\n" +
|
||
|
" \"price\": 8.99\n" +
|
||
|
" },\n" +
|
||
|
" { \"category\": \"fiction\",\n" +
|
||
|
" \"author\": \"J. R. R. Tolkien\",\n" +
|
||
|
" \"title\": \"The Lord of the Rings\",\n" +
|
||
|
" \"isbn\": \"0-395-19395-8\",\n" +
|
||
|
" \"price\": 22.99\n" +
|
||
|
" }\n" +
|
||
|
" ],\n" +
|
||
|
" \"bicycle\": {\n" +
|
||
|
" \"color\": \"red\",\n" +
|
||
|
" \"price\": 19.95,\n" +
|
||
|
" \"foo:bar\": \"fooBar\",\n" +
|
||
|
" \"dot.notation\": \"new\"\n" +
|
||
|
" }\n" +
|
||
|
" }\n" +
|
||
|
"}";
|
||
|
|
||
|
@Test
|
||
|
public void a_path_can_be_read() throws Exception {
|
||
|
|
||
14 years ago
|
JsonModel pathReader = JsonModel.create(DOCUMENT);
|
||
14 years ago
|
|
||
|
Map<String, Object> book = pathReader.read("store.book[1]");
|
||
|
|
||
14 years ago
|
JsonModel pathReader1 = pathReader.get("store.book[1]");
|
||
14 years ago
|
|
||
|
String author = pathReader1.read("author");
|
||
|
|
||
|
System.out.println("d");
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|