JsonPath NoClassDefFoundError, oder eine alternative zu JsonPath in Java

Für Gründen im Zusammenhang mit dem Projekt an dem ich arbeite, möchte ich eine komplette Abfrage an eine JSON-Datei gehalten werden als eine Zeichenkette, zum Beispiel $.store.book[*].title (anstatt zu speichern Sie jede Ebene des Dokuments vorübergehend als separates Objekt).

Ich bin derzeit mit JsonPath (version 0.8.0, die war die neueste, die ich finden konnte), das ist im Grunde genau das, was ich Suche, aber ich bin immer die Ausnahme, die unten gezeigt. Ich bin nur mit der Beispiel-JSON auf dem JsonPath google-code-Seite, die mit einem Ihrer Probe Abfragen.

Was mache ich hier falsch? Alternativ, wenn es nicht eine Lösung, gibt es alternativen zu JsonPath in Java? Ich möchte in der Lage sein, um eine komplette Abfrage als string und es muss Java sein.

Funktion:

public void testJsonPath() throws Exception
{
    String query = "$.store.book[*].title";
    List toRet = (List) JsonPath.read(practiceJson, query, new Filter[0]);
    System.out.println(toRet.toString());
}

Ausnahme:

java.lang.NoClassDefFoundError: net/minidev/json/parser/ParseException
at com.jayway.jsonpath.spi.JsonProviderFactory$1.create(JsonProviderFactory.java:27)
at com.jayway.jsonpath.spi.JsonProviderFactory.createProvider(JsonProviderFactory.java:32)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:202)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:307)
at net.windward.datasource.test.TestJsonDataSource.testJsonPath(TestJsonDataSource.java:119)

Die Praxis JSON:

private String practiceJson = "{\n" +
        "    \"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" +
        "        \"bicycle\": [ {\n" +
        "            \"color\": \"red\",\n" +
        "            \"price\": 19.95,\n" +
        "            \"style\": [ \"city\", \"hybrid\" ]\n" +
        "        }, {\n" +
        "            \"color\": \"blue\",\n" +
        "            \"price\": 59.91,\n" +
        "            \"style\": [ \"downhill\", \"freeride\" ]\n" +
        "        } ]\n" +
        "    }\n" +
        "}";
InformationsquelleAutor firechant | 2013-07-18
Schreibe einen Kommentar