Search in sources :

Example 1 with JacksonJsonProvider

use of com.jayway.jsonpath.spi.json.JacksonJsonProvider in project metron by apache.

the class JSONMapParser method configure.

@Override
public void configure(Map<String, Object> config) {
    String strategyStr = (String) config.getOrDefault(MAP_STRATEGY_CONFIG, MapStrategy.DROP.name());
    mapStrategy = MapStrategy.valueOf(strategyStr);
    if (config.containsKey(JSONP_QUERY)) {
        jsonpQuery = (String) config.get(JSONP_QUERY);
        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.of(Option.SUPPRESS_EXCEPTIONS);
            }
        });
        if (CacheProvider.getCache() == null) {
            CacheProvider.setCache(new LRUCache(100));
        }
    }
}
Also used : JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) LRUCache(com.jayway.jsonpath.spi.cache.LRUCache) Set(java.util.Set) EnumSet(java.util.EnumSet) Configuration(com.jayway.jsonpath.Configuration) JacksonJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonProvider) JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) MappingProvider(com.jayway.jsonpath.spi.mapper.MappingProvider) JacksonJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonProvider) JsonProvider(com.jayway.jsonpath.spi.json.JsonProvider)

Example 2 with JacksonJsonProvider

use of com.jayway.jsonpath.spi.json.JacksonJsonProvider in project JsonPath by json-path.

the class JsonProviderTest method parse_document.

@Test
public void parse_document() throws Exception {
    JacksonJsonProvider provider = new JacksonJsonProvider();
    Object o = provider.parse(DOCUMENT);
}
Also used : JacksonJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonProvider) Test(org.junit.Test)

Example 3 with JacksonJsonProvider

use of com.jayway.jsonpath.spi.json.JacksonJsonProvider in project JsonPath by json-path.

the class ProviderInTest method testJsonPathQuotesJackson.

@Test
public void testJsonPathQuotesJackson() throws Exception {
    final Configuration jackson = Configuration.builder().jsonProvider(new JacksonJsonProvider()).mappingProvider(new JacksonMappingProvider()).build();
    final DocumentContext ctx = JsonPath.using(jackson).parse(JSON);
    final List<String> doubleQuoteEqualsResult = ctx.read(DOUBLE_QUOTES_EQUALS_FILTER);
    assertEquals(Lists.newArrayList("bar"), doubleQuoteEqualsResult);
    final List<String> singleQuoteEqualsResult = ctx.read(SINGLE_QUOTES_EQUALS_FILTER);
    assertEquals(doubleQuoteEqualsResult, singleQuoteEqualsResult);
    final List<String> doubleQuoteInResult = ctx.read(DOUBLE_QUOTES_IN_FILTER);
    assertEquals(doubleQuoteInResult, doubleQuoteEqualsResult);
    final List<String> singleQuoteInResult = ctx.read(SINGLE_QUOTES_IN_FILTER);
    assertEquals(doubleQuoteInResult, singleQuoteInResult);
}
Also used : JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) JacksonJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonProvider) Test(org.junit.Test)

Example 4 with JacksonJsonProvider

use of com.jayway.jsonpath.spi.json.JacksonJsonProvider in project JsonPath by json-path.

the class Bench method runNebhale.

public Result runNebhale() {
    String result = null;
    String error = null;
    long time;
    Object res = null;
    JacksonJsonProvider jacksonProvider = new JacksonJsonProvider();
    long now = System.currentTimeMillis();
    try {
        if (!optionAsValues) {
            throw new UnsupportedOperationException("Not supported!");
        }
        com.nebhale.jsonpath.JsonPath compiled = com.nebhale.jsonpath.JsonPath.compile(path);
        res = compiled.read(json, Object.class);
    } catch (Exception e) {
        error = getError(e);
    } finally {
        time = System.currentTimeMillis() - now;
        result = res != null ? jacksonProvider.toJson(res) : null;
        return new Result("nebhale", time, result, error);
    }
}
Also used : JacksonJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonProvider)

Example 5 with JacksonJsonProvider

use of com.jayway.jsonpath.spi.json.JacksonJsonProvider in project xm-ms-entity by xm-online.

the class FixedDefaultJsonUnmarshaller method unmarshal.

@Override
public <T> T unmarshal(final Class<T> resultClass, final String json) throws IOException {
    final JacksonJsonProvider jacksonJsonProvider = new JacksonJsonProvider(objectMapper);
    final Configuration jwayConfiguration = Configuration.defaultConfiguration().jsonProvider(jacksonJsonProvider);
    // for JSONPath
    final ReadContext jwayReadContext = using(jwayConfiguration).parse(json);
    try {
        return recursivelyProcessAllFields(resultClass.newInstance(), jwayReadContext, new ArrayList<String>());
    } catch (InstantiationException | IllegalAccessException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : Configuration(com.jayway.jsonpath.Configuration) JacksonJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonProvider) ReadContext(com.jayway.jsonpath.ReadContext)

Aggregations

JacksonJsonProvider (com.jayway.jsonpath.spi.json.JacksonJsonProvider)15 JacksonMappingProvider (com.jayway.jsonpath.spi.mapper.JacksonMappingProvider)8 Test (org.junit.Test)8 Configuration (com.jayway.jsonpath.Configuration)4 JsonProvider (com.jayway.jsonpath.spi.json.JsonProvider)3 MappingProvider (com.jayway.jsonpath.spi.mapper.MappingProvider)3 EnumSet (java.util.EnumSet)3 Set (java.util.Set)3 Option (com.jayway.jsonpath.Option)2 Defaults (com.jayway.jsonpath.Configuration.Defaults)1 ReadContext (com.jayway.jsonpath.ReadContext)1 LRUCache (com.jayway.jsonpath.spi.cache.LRUCache)1 AssetsBundle (io.dropwizard.assets.AssetsBundle)1 MultiPartBundle (io.dropwizard.forms.MultiPartBundle)1 ConnectorTemplate (io.syndesis.common.model.connection.ConnectorTemplate)1 List (java.util.List)1 Map (java.util.Map)1