Search in sources :

Example 1 with MappingProvider

use of com.jayway.jsonpath.spi.mapper.MappingProvider in project spring-data-commons by spring-projects.

the class JsonProjectingMethodInterceptorFactoryUnitTests method setUp.

@Before
public void setUp() {
    String json = // 
    "{\"firstname\" : \"Dave\", " + // 
    "\"address\" : { \"zipCode\" : \"01097\", \"city\" : \"Dresden\" }," + "\"addresses\" : [ { \"zipCode\" : \"01097\", \"city\" : \"Dresden\" }]" + " }";
    SpelAwareProxyProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
    MappingProvider mappingProvider = new JacksonMappingProvider(new ObjectMapper());
    projectionFactory.registerMethodInvokerFactory(new JsonProjectingMethodInterceptorFactory(mappingProvider));
    this.projectionFactory = projectionFactory;
    this.customer = projectionFactory.createProjection(Customer.class, new ByteArrayInputStream(json.getBytes()));
}
Also used : JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) MappingProvider(com.jayway.jsonpath.spi.mapper.MappingProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 2 with MappingProvider

use of com.jayway.jsonpath.spi.mapper.MappingProvider in project metron by apache.

the class JSONMapParser method configure.

@Override
public void configure(Map<String, Object> config) {
    setReadCharset(config);
    String strategyStr = (String) config.getOrDefault(MAP_STRATEGY_CONFIG, MapStrategy.DROP.name());
    mapStrategy = MapStrategy.valueOf(strategyStr);
    overrideOriginalString = (Boolean) config.getOrDefault(OVERRIDE_ORIGINAL_STRING, false);
    if (config.containsKey(JSONP_QUERY)) {
        typeRef = new TypeRef<List<Map<String, Object>>>() {
        };
        jsonpQuery = (String) config.get(JSONP_QUERY);
        if (!StringUtils.isBlank(jsonpQuery) && config.containsKey(WRAP_JSON)) {
            Object wrapObject = config.get(WRAP_JSON);
            if (wrapObject instanceof String) {
                wrapJson = Boolean.valueOf((String) wrapObject);
            } else if (wrapObject instanceof Boolean) {
                wrapJson = (Boolean) config.get(WRAP_JSON);
            }
            String entityName = (String) config.get(WRAP_ENTITY_NAME);
            if (!StringUtils.isBlank(entityName)) {
                wrapEntityName = entityName;
            }
        }
        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 : 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) JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) LRUCache(com.jayway.jsonpath.spi.cache.LRUCache) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.simple.JSONObject)

Example 3 with MappingProvider

use of com.jayway.jsonpath.spi.mapper.MappingProvider in project geode by apache.

the class UseJacksonForJsonPathRule method before.

/**
   * 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);
        }
    });
}
Also used : JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) Defaults(com.jayway.jsonpath.Configuration.Defaults) Set(java.util.Set) EnumSet(java.util.EnumSet) JacksonJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonProvider) MappingProvider(com.jayway.jsonpath.spi.mapper.MappingProvider) JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) Option(com.jayway.jsonpath.Option) JacksonJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonProvider) JsonProvider(com.jayway.jsonpath.spi.json.JsonProvider)

Example 4 with MappingProvider

use of com.jayway.jsonpath.spi.mapper.MappingProvider in project irontest by zheng-wang.

the class IronTestApplication method initialize.

@Override
public void initialize(Bootstrap<IronTestConfiguration> bootstrap) {
    bootstrap.addBundle(new AssetsBundle("/assets/app", "/ui", "index.htm", "ui"));
    bootstrap.addBundle(new AssetsBundle("/META-INF/resources/webjars", "/ui/lib", null, "lib"));
    bootstrap.addBundle(new AssetsBundle("/assets/mockserver", "/ui/mockserver", "mockserver.htm", "mockserver"));
    bootstrap.addBundle(new AssetsBundle("/assets/common", "/ui/common", null, "common"));
    bootstrap.addBundle(jaxWsBundle);
    bootstrap.addBundle(new MultiPartBundle());
    bootstrap.addBundle(new ViewBundle<IronTestConfiguration>() {

        @Override
        public Map<String, Map<String, String>> getViewConfiguration(IronTestConfiguration config) {
            return config.getViewRendererConfiguration();
        }
    });
    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);
        }
    });
    // configure the Jackson ObjectMapper used by JAX-RS (Jersey)
    ObjectMapper objectMapper = bootstrap.getObjectMapper();
    objectMapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
    IronTestUtils.addMixInsForWireMock(objectMapper);
}
Also used : MultiPartBundle(io.dropwizard.forms.MultiPartBundle) EnumSet(java.util.EnumSet) Set(java.util.Set) Configuration(com.jayway.jsonpath.Configuration) JacksonJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonProvider) AssetsBundle(io.dropwizard.assets.AssetsBundle) JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) MappingProvider(com.jayway.jsonpath.spi.mapper.MappingProvider) JsonProvider(com.jayway.jsonpath.spi.json.JsonProvider) JacksonJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonProvider) JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) Option(com.jayway.jsonpath.Option) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with MappingProvider

use of com.jayway.jsonpath.spi.mapper.MappingProvider in project MtgDesktopCompanion by nicho92.

the class MtgjsonProvider method init.

public void init() {
    logger.info("init " + this);
    Configuration.setDefaults(new Configuration.Defaults() {

        private final JsonProvider jsonProvider = new GsonJsonProvider();

        private final MappingProvider mappingProvider = new GsonMappingProvider();

        @Override
        public JsonProvider jsonProvider() {
            return jsonProvider;
        }

        @Override
        public MappingProvider mappingProvider() {
            return mappingProvider;
        }

        @Override
        public Set<Option> options() {
            return EnumSet.noneOf(Option.class);
        }
    });
    Configuration.defaultConfiguration().addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL);
    try {
        logger.debug("loading file " + fileSetJson);
        if (!fileSetJson.exists() || fileSetJson.length() == 0) {
            logger.info("datafile does not exist. Downloading it");
            FileUtils.copyInputStreamToFile(getStreamFromUrl(new URL(getString("URL_SET_JSON_ZIP"))), fileSetJsonTemp);
            unZipIt();
            FileUtils.copyInputStreamToFile(getStreamFromUrl(new URL(getString("URL_VERSION"))), fversion);
        }
        if (hasNewVersion()) {
            FileUtils.copyInputStreamToFile(getStreamFromUrl(new URL(getString("URL_SET_JSON_ZIP"))), fileSetJsonTemp);
            unZipIt();
            FileUtils.copyInputStreamToFile(getStreamFromUrl(new URL(getString("URL_VERSION"))), fversion);
        }
        cachedCardEds = new HashMap<>();
        logger.info(this + " : parsing db file");
        long time1 = System.currentTimeMillis();
        ctx = JsonPath.parse(fileSetJson);
        long time2 = System.currentTimeMillis();
        logger.info(this + " : parsing OK (" + (time2 - time1) / 1000 + " s)");
    } catch (Exception e1) {
        logger.error(e1);
    }
}
Also used : GsonMappingProvider(com.jayway.jsonpath.spi.mapper.GsonMappingProvider) EnumSet(java.util.EnumSet) Set(java.util.Set) Configuration(com.jayway.jsonpath.Configuration) GsonMappingProvider(com.jayway.jsonpath.spi.mapper.GsonMappingProvider) MappingProvider(com.jayway.jsonpath.spi.mapper.MappingProvider) JsonProvider(com.jayway.jsonpath.spi.json.JsonProvider) GsonJsonProvider(com.jayway.jsonpath.spi.json.GsonJsonProvider) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) PathNotFoundException(com.jayway.jsonpath.PathNotFoundException) GsonJsonProvider(com.jayway.jsonpath.spi.json.GsonJsonProvider) Option(com.jayway.jsonpath.Option)

Aggregations

MappingProvider (com.jayway.jsonpath.spi.mapper.MappingProvider)5 JsonProvider (com.jayway.jsonpath.spi.json.JsonProvider)4 JacksonMappingProvider (com.jayway.jsonpath.spi.mapper.JacksonMappingProvider)4 EnumSet (java.util.EnumSet)4 Set (java.util.Set)4 Configuration (com.jayway.jsonpath.Configuration)3 Option (com.jayway.jsonpath.Option)3 JacksonJsonProvider (com.jayway.jsonpath.spi.json.JacksonJsonProvider)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Defaults (com.jayway.jsonpath.Configuration.Defaults)1 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)1 LRUCache (com.jayway.jsonpath.spi.cache.LRUCache)1 GsonJsonProvider (com.jayway.jsonpath.spi.json.GsonJsonProvider)1 GsonMappingProvider (com.jayway.jsonpath.spi.mapper.GsonMappingProvider)1 AssetsBundle (io.dropwizard.assets.AssetsBundle)1 MultiPartBundle (io.dropwizard.forms.MultiPartBundle)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1