本文整理汇总了Java中com.jayway.jsonpath.Option类的典型用法代码示例。如果您正苦于以下问题:Java Option类的具体用法?Java Option怎么用?Java Option使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Option类属于com.jayway.jsonpath包,在下文中一共展示了Option类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: before
import com.jayway.jsonpath.Option; //导入依赖的package包/类
/**
* Override to set up your specific external resource.
*/
@Override
public void before() {
saveDefaults();
Configuration.setDefaults(new Defaults() {
private final JsonProvider jsonProvider = new JacksonJsonProvider();
private final MappingProvider mappingProvider = new JacksonMappingProvider();
@Override
public JsonProvider jsonProvider() {
return jsonProvider;
}
@Override
public MappingProvider mappingProvider() {
return mappingProvider;
}
@Override
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
}
});
}
示例2: restoreDefaults
import com.jayway.jsonpath.Option; //导入依赖的package包/类
private void restoreDefaults() {
if (!this.hadDefaults) {
return;
}
Configuration.setDefaults(new Defaults() {
@Override
public JsonProvider jsonProvider() {
return jsonProvider;
}
@Override
public MappingProvider mappingProvider() {
return mappingProvider;
}
@Override
public Set<Option> options() {
return options;
}
});
}
示例3: init
import com.jayway.jsonpath.Option; //导入依赖的package包/类
@SuppressWarnings("WeakerAccess")
public void init(){
// jsonpath配置初始化
com.jayway.jsonpath.Configuration.setDefaults(new com.jayway.jsonpath.Configuration.Defaults() {
private final JsonProvider jsonProvider = new JacksonJsonProvider();
private final MappingProvider mappingProvider = new JacksonMappingProvider();
@Override
public JsonProvider jsonProvider() {
return jsonProvider;
}
@Override
public MappingProvider mappingProvider() {
return mappingProvider;
}
@Override
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
}
});
}
示例4: setUp
import com.jayway.jsonpath.Option; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
com.jayway.jsonpath.Configuration.setDefaults(new com.jayway.jsonpath.Configuration.Defaults() {
private final JsonProvider jsonProvider = new JacksonJsonProvider();
private final MappingProvider mappingProvider = new JacksonMappingProvider();
@Override
public JsonProvider jsonProvider() {
return jsonProvider;
}
@Override
public MappingProvider mappingProvider() {
return mappingProvider;
}
@Override
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
}
});
}
示例5: setDefaults
import com.jayway.jsonpath.Option; //导入依赖的package包/类
public static void setDefaults() {
Configuration.setDefaults(new Configuration.Defaults() {
private final JsonProvider jsonProvider = new JacksonJsonProvider();
private final MappingProvider mappingProvider = new JacksonMappingProvider();
@Override
public JsonProvider jsonProvider() {
return jsonProvider;
}
@Override
public MappingProvider mappingProvider() {
return mappingProvider;
}
@Override
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
}
});
}
示例6: evaluate
import com.jayway.jsonpath.Option; //导入依赖的package包/类
@Override
public void evaluate(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) {
if (ctx.jsonProvider().isMap(model)) {
for (String property : ctx.jsonProvider().getPropertyKeys(model)) {
handleObjectProperty(currentPath, model, ctx, asList(property));
}
} else if (ctx.jsonProvider().isArray(model)) {
for (int idx = 0; idx < ctx.jsonProvider().length(model); idx++) {
try {
handleArrayIndex(idx, currentPath, model, ctx);
} catch (PathNotFoundException p){
if(ctx.options().contains(Option.REQUIRE_PROPERTIES)){
throw p;
}
}
}
}
}
示例7: SelectJsonPath
import com.jayway.jsonpath.Option; //导入依赖的package包/类
@Inject
public SelectJsonPath(ObjectMapper objectMapper) {
configuration = Configuration.builder()
.options(Option.SUPPRESS_EXCEPTIONS)
.jsonProvider(new JacksonJsonNodeJsonProvider(objectMapper))
.build();
jsonParam = ParameterDescriptor.type("json", JsonNode.class).description("A parsed JSON tree").build();
// sigh generics and type erasure
//noinspection unchecked
pathsParam = ParameterDescriptor.type("paths",
(Class<Map<String, String>>) new TypeLiteral<Map<String, String>>() {}.getRawType(),
(Class<Map<String, JsonPath>>) new TypeLiteral<Map<String, JsonPath>>() {}.getRawType())
.transform(inputMap -> inputMap
.entrySet().stream()
.collect(toMap(Map.Entry::getKey, e -> JsonPath.compile(e.getValue()))))
.description("A map of names to a JsonPath expression, see http://jsonpath.com")
.build();
}
示例8: afterPropertiesSet
import com.jayway.jsonpath.Option; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
Configuration.setDefaults(new Configuration.Defaults() {
private final JsonProvider jsonProvider = new JacksonJsonProvider();
@Override
public JsonProvider jsonProvider() {
return jsonProvider;
}
@Override
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
}
@Override
public MappingProvider mappingProvider() {
return new JacksonMappingProvider();
}
});
}
示例9: createExpression
import com.jayway.jsonpath.Option; //导入依赖的package包/类
@Override
public Expression createExpression(CamelContext camelContext, Annotation annotation,
LanguageAnnotation languageAnnotation, Class<?> expressionReturnType) {
String expression = getExpressionFromAnnotation(annotation);
JsonPathExpression answer = new JsonPathExpression(expression);
if (expressionReturnType != null) {
answer.setResultType(expressionReturnType);
}
if (annotation instanceof JsonPath) {
JsonPath jsonPathAnnotation = (JsonPath) annotation;
answer.setSuppressExceptions(jsonPathAnnotation.suppressExceptions());
Option[] options = jsonPathAnnotation.options();
answer.setOptions(options);
}
answer.init();
return answer;
}
示例10: save
import com.jayway.jsonpath.Option; //导入依赖的package包/类
public void save(@NotNull SchemaFormContentAware newEntity, SchemaFormContentAware oldEntity, String entityPath) {
Assert.notNull(newEntity, "New content cannot be null");
Object json = defaultConfiguration().jsonProvider().parse(newEntity.getContent());
DocumentContext newContext = JsonPath.using(defaultConfiguration().addOptions(Option.AS_PATH_LIST)).parse(json);
Map<String, JSONArray> newPaths = getPathFilesMap(newContext, json);
if (newPaths == null) return; // content does not have any file field
if (oldEntity != null) {
Object oldJson = defaultConfiguration().jsonProvider().parse(oldEntity.getContent());
DocumentContext oldContext = JsonPath.using(defaultConfiguration().addOptions(Option.AS_PATH_LIST)).parse(oldJson);
Map<String, JSONArray> oldPaths = getPathFilesMap(oldContext, oldJson);
if (oldPaths != null) {
saveAndDelete(oldPaths, newPaths, entityPath);
} else {
// schema and definition now have files
newPaths.values().forEach(v -> saveFiles(v, entityPath));
}
} else {
newPaths.values().forEach(v -> saveFiles(v, entityPath));
}
cleanup(newPaths, newContext);
newEntity.setContent(newContext.jsonString());
}
示例11: test
import com.jayway.jsonpath.Option; //导入依赖的package包/类
@Test
public void test() throws ScriptException {
com.jayway.jsonpath.Configuration.setDefaults(new com.jayway.jsonpath.Configuration.Defaults() {
private final JsonProvider jsonProvider = new JacksonJsonProvider();
private final MappingProvider mappingProvider = new JacksonMappingProvider();
@Override
public JsonProvider jsonProvider() {
return jsonProvider;
}
@Override
public MappingProvider mappingProvider() {
return mappingProvider;
}
@Override
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
}
});
// DocumentContext doc = JsonPath.parse(this.getClass().getClassLoader().getResourceAsStream("nashorn.js")); //InvalidJsonException
// TestSuit testSuit = doc.read("$", TestSuit.class);
ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
ScriptEngine nashorn = scriptEngineManager.getEngineByName("nashorn");
nashorn.eval(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("nashorn.js")));//ScriptException->ParserException
Object obj = nashorn.eval("JSON.stringify(testSuit)");
System.out.println(obj);
}
示例12: replace
import com.jayway.jsonpath.Option; //导入依赖的package包/类
public Map<String, Object> replace(Map<String, Object> input, Object json) {
Object doc = null;
if(json instanceof String) {
doc = JsonPath.parse(json.toString());
} else {
doc = json;
}
Configuration option = Configuration.defaultConfiguration().addOptions(Option.SUPPRESS_EXCEPTIONS);
DocumentContext io = JsonPath.parse(doc, option);
return replace(input, io, null);
}
示例13: set
import com.jayway.jsonpath.Option; //导入依赖的package包/类
@Override
public DocumentContext set(JsonPath path, Object newValue){
List<String> modified = path.set(json, newValue, configuration.addOptions(Option.AS_PATH_LIST));
if(logger.isDebugEnabled()){
for (String p : modified) {
logger.debug("Set path {} new value {}", p, newValue);
}
}
return this;
}
示例14: delete
import com.jayway.jsonpath.Option; //导入依赖的package包/类
@Override
public DocumentContext delete(JsonPath path) {
List<String> modified = path.delete(json, configuration.addOptions(Option.AS_PATH_LIST));
if(logger.isDebugEnabled()){
for (String p : modified) {
logger.debug("Delete path {}");
}
}
return this;
}
示例15: add
import com.jayway.jsonpath.Option; //导入依赖的package包/类
@Override
public DocumentContext add(JsonPath path, Object value){
List<String> modified = path.add(json, value, configuration.addOptions(Option.AS_PATH_LIST));
if(logger.isDebugEnabled()){
for (String p : modified) {
logger.debug("Add path {} new value {}", p, value);
}
}
return this;
}