Browse Source

Fixed bug with multiple properties.

$.store.book[0]['title', 'author']
pull/41/head
Kalle Stenflo 10 years ago
parent
commit
ac83eb0934
  1. 1
      json-path/src/main/java/com/jayway/jsonpath/internal/spi/compiler/EvaluationContextImpl.java
  2. 11
      json-path/src/main/java/com/jayway/jsonpath/internal/spi/compiler/PathCompiler.java

1
json-path/src/main/java/com/jayway/jsonpath/internal/spi/compiler/EvaluationContextImpl.java

@ -82,4 +82,5 @@ class EvaluationContextImpl implements EvaluationContext {
public List<String> getPathList() {
return pathResult;
}
}

11
json-path/src/main/java/com/jayway/jsonpath/internal/spi/compiler/PathCompiler.java

@ -42,7 +42,8 @@ public class PathCompiler {
path = "$." + path;
}
Path p = cache.get(path + filterList.toString());
String cacheKey = path + filterList.toString();
Path p = cache.get(cacheKey);
if(p != null){
return p;
}
@ -110,7 +111,7 @@ public class PathCompiler {
Path pa = new CompiledPath(root);
cache.put(path, pa);
cache.put(cacheKey, pa);
return pa;
}
@ -344,6 +345,7 @@ public class PathCompiler {
StringBuilder buffer = new StringBuilder();
boolean propertyIsOpen = false;
boolean propertyDone = false;
while (current != ']') {
switch (current) {
@ -351,12 +353,17 @@ public class PathCompiler {
if (propertyIsOpen) {
property = buffer.toString();
propertyIsOpen = false;
propertyDone = true;
} else {
propertyIsOpen = true;
}
break;
default:
if (propertyIsOpen) {
if(propertyDone){
//Don't understand how to create a "Normalized path expressions" for this type of query
throw new InvalidPathException("Only single properties are supported.");
}
buffer.append(current);
}
break;

Loading…
Cancel
Save