json-path / JsonPath

Java JsonPath implementation
Apache License 2.0
8.96k stars 1.65k forks source link

JsonPath annotation root path exception #336

Open mahmutGuru opened 7 years ago

mahmutGuru commented 7 years ago

Hi,

When we try to get the root as a field in the object, we get the error:

com.jayway.jsonpath.InvalidPathException: Path must not end with a '.' or '..'
    at com.jayway.jsonpath.internal.path.PathCompiler.fail(PathCompiler.java:607) ~[json-path-2.2.0.jar:2.2.0]
    at com.jayway.jsonpath.internal.path.PathCompiler.compile(PathCompiler.java:66) ~[json-path-2.2.0.jar:2.2.0]
    at com.jayway.jsonpath.JsonPath.<init>(JsonPath.java:101) ~[json-path-2.2.0.jar:2.2.0]
    at com.jayway.jsonpath.JsonPath.compile(JsonPath.java:467) ~[json-path-2.2.0.jar:2.2.0]
    at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:149) ~[json-path-2.2.0.jar:2.2.0]
    at com.fasterxml.jackson.contrib.jsonpath.DefaultJsonUnmarshaller.readValueFromJsonTree(DefaultJsonUnmarshaller.java:241) ~[json-unmarshaller-1.1.1.jar:?]
    at com.fasterxml.jackson.contrib.jsonpath.DefaultJsonUnmarshaller.performJsonPathUnmarshalling(DefaultJsonUnmarshaller.java:194) ~[json-unmarshaller-1.1.1.jar:?]
    at com.fasterxml.jackson.contrib.jsonpath.DefaultJsonUnmarshaller.recursivelyProcessAllFields(DefaultJsonUnmarshaller.java:106) ~[json-unmarshaller-1.1.1.jar:?]
    at com.fasterxml.jackson.contrib.jsonpath.DefaultJsonUnmarshaller.unmarshal(DefaultJsonUnmarshaller.java:63) ~[json-unmarshaller-1.1.1.jar:?]

the usage is like this:

@JsonPath("$")

kallestenflo commented 7 years ago

I don't understand the issue. Can you provide an example?

Docs can be found here : https://github.com/jayway/JsonPath

mahmutGuru commented 7 years ago

sure, for ex:

class AAA {
    @JsonPath("$")
    private Map<String, Object> details;
}

when I do this, the exception occurs. In here, I just want the whole json as a Map in my class.

kallestenflo commented 7 years ago

This library does not have any annotations. You are targeting the wrong project. Check what package the annotation belongs to.

jochenberger commented 7 years ago

I guess this can be closed.