Browse Source

Added ability for Predicates to get items from the PredicateContext using a TypeRef<T>

pull/61/head
Harland Sanders 10 years ago
parent
commit
ddcbd9a623
  1. 7
      json-path/src/main/java/com/jayway/jsonpath/Predicate.java
  2. 6
      json-path/src/main/java/com/jayway/jsonpath/internal/token/PredicateContextImpl.java

7
json-path/src/main/java/com/jayway/jsonpath/Predicate.java

@ -38,6 +38,13 @@ public interface Predicate {
*/ */
<T> T item(Class<T> clazz) throws MappingException; <T> T item(Class<T> clazz) throws MappingException;
/**
* Returns the current item being evaluated by this predicate. It will be mapped
* to the type of the provided TypeRef
* @return current document
*/
<T> T item(TypeRef<T> typeRef) throws MappingException;
/** /**
* Returns the root document (the complete JSON) * Returns the root document (the complete JSON)
* @return root document * @return root document

6
json-path/src/main/java/com/jayway/jsonpath/internal/token/PredicateContextImpl.java

@ -16,6 +16,7 @@ package com.jayway.jsonpath.internal.token;
import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Predicate; import com.jayway.jsonpath.Predicate;
import com.jayway.jsonpath.TypeRef;
import com.jayway.jsonpath.internal.Path; import com.jayway.jsonpath.internal.Path;
import com.jayway.jsonpath.spi.mapper.MappingException; import com.jayway.jsonpath.spi.mapper.MappingException;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -69,6 +70,11 @@ public class PredicateContextImpl implements Predicate.PredicateContext {
return configuration().mappingProvider().map(contextDocument, clazz, configuration); return configuration().mappingProvider().map(contextDocument, clazz, configuration);
} }
@Override
public <T> T item(TypeRef<T> typeRef) throws MappingException {
return configuration().mappingProvider().map(contextDocument, typeRef, configuration);
}
@Override @Override
public Object root() { public Object root() {
return rootDocument; return rootDocument;

Loading…
Cancel
Save