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() { public List<String> getPathList() {
return pathResult; 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 = "$." + path;
} }
Path p = cache.get(path + filterList.toString()); String cacheKey = path + filterList.toString();
Path p = cache.get(cacheKey);
if(p != null){ if(p != null){
return p; return p;
} }
@ -110,7 +111,7 @@ public class PathCompiler {
Path pa = new CompiledPath(root); Path pa = new CompiledPath(root);
cache.put(path, pa); cache.put(cacheKey, pa);
return pa; return pa;
} }
@ -344,6 +345,7 @@ public class PathCompiler {
StringBuilder buffer = new StringBuilder(); StringBuilder buffer = new StringBuilder();
boolean propertyIsOpen = false; boolean propertyIsOpen = false;
boolean propertyDone = false;
while (current != ']') { while (current != ']') {
switch (current) { switch (current) {
@ -351,12 +353,17 @@ public class PathCompiler {
if (propertyIsOpen) { if (propertyIsOpen) {
property = buffer.toString(); property = buffer.toString();
propertyIsOpen = false; propertyIsOpen = false;
propertyDone = true;
} else { } else {
propertyIsOpen = true; propertyIsOpen = true;
} }
break; break;
default: default:
if (propertyIsOpen) { 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); buffer.append(current);
} }
break; break;

Loading…
Cancel
Save