Java Code Examples for com.jayway.jsonpath.spi.mapper.MappingProvider

The following examples show how to use com.jayway.jsonpath.spi.mapper.MappingProvider. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void setJsonPathConfiguration() {
    Configuration.setDefaults(new Configuration.Defaults() {

        private final JsonProvider jsonProvider = new GsonJsonProvider(new GsonBuilder().serializeNulls().create());
        private final MappingProvider mappingProvider = new GsonMappingProvider();

        public JsonProvider jsonProvider() {
            return jsonProvider;
        }

        public MappingProvider mappingProvider() {
            return mappingProvider;
        }

        public Set<Option> options() {
            return EnumSet.noneOf(Option.class);
        }
    });
}
 
Example 2
@BeforeEach
void configureJsonPath() {
	Configuration.setDefaults(new Configuration.Defaults() {
		private final JsonProvider jacksonJsonProvider = new JacksonJsonProvider();

		private final MappingProvider jacksonMappingProvider = new JacksonMappingProvider();

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

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

		@Override
		public Set<Option> options() {
			return EnumSet.noneOf(Option.class);
		}
	});
}
 
Example 3
Source Project: interface-test   Source File: InterfaceTestApplication.java    License: Apache License 2.0 6 votes vote down vote up
@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);
        }
    });
}
 
Example 4
Source Project: interface-test   Source File: TestCaseLoaderTest.java    License: Apache License 2.0 6 votes vote down vote up
@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);
        }
    });
}
 
Example 5
Source Project: light-4j   Source File: MaskTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void runOnceBeforeClass() {
    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);
        }
    });
}
 
Example 6
Source Project: light-4j   Source File: JsonPathStartupHookProvider.java    License: Apache License 2.0 6 votes vote down vote up
static void configJsonPath() {
    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);
        }
    });
}
 
Example 7
Source Project: product-ei   Source File: ForEachnativeJSONTestCase.java    License: Apache License 2.0 6 votes vote down vote up
private void setJsonPathConfiguration() {
    Configuration.setDefaults(new Configuration.Defaults() {

        private final JsonProvider jsonProvider = new GsonJsonProvider(new GsonBuilder().serializeNulls().create());
        private final MappingProvider mappingProvider = new GsonMappingProvider();

        public JsonProvider jsonProvider() {
            return jsonProvider;
        }

        public MappingProvider mappingProvider() {
            return mappingProvider;
        }

        public Set<Option> options() {
            return EnumSet.noneOf(Option.class);
        }
    });
}
 
Example 8
private void setJsonPathConfiguration() {
    Configuration.setDefaults(new Configuration.Defaults() {

        private final JsonProvider jsonProvider = new GsonJsonProvider(new GsonBuilder().serializeNulls().create());
        private final MappingProvider mappingProvider = new GsonMappingProvider();

        public JsonProvider jsonProvider() {
            return jsonProvider;
        }

        public MappingProvider mappingProvider() {
            return mappingProvider;
        }

        public Set<Option> options() {
            return EnumSet.noneOf(Option.class);
        }
    });
}
 
Example 9
Source Project: carbon-apimgt   Source File: TestSchemaValidator.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() {
    // Set GsonJsonProvider as the default Jayway JSON path default configuration
    // Which is set by synapse-core at runtime of the server
    Configuration.setDefaults(new Configuration.Defaults() {
        private final JsonProvider jsonProvider = new GsonJsonProvider(new GsonBuilder().serializeNulls().create());
        private final MappingProvider mappingProvider = new GsonMappingProvider();

        public JsonProvider jsonProvider() {
            return jsonProvider;
        }

        public MappingProvider mappingProvider() {
            return mappingProvider;
        }

        public Set<Option> options() {
            return EnumSet.noneOf(Option.class);
        }
    });
}
 
Example 10
Source Project: light   Source File: LightServer.java    License: Apache License 2.0 6 votes vote down vote up
static void configJsonPath() {
    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);
        }
    });
}
 
Example 11
Source Project: interface-test   Source File: NashornTest.java    License: Apache License 2.0 5 votes vote down vote up
@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);


    }
 
Example 12
Source Project: vividus   Source File: JsonPathUtils.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public MappingProvider mappingProvider()
{
    return jacksonMappingProvider;
}
 
Example 13
Source Project: centraldogma   Source File: Jackson.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public MappingProvider mappingProvider() {
    return jsonPathCfg.mappingProvider();
}
 
Example 14
Source Project: karate   Source File: JsonUtils.java    License: MIT License 4 votes vote down vote up
@Override
public MappingProvider mappingProvider() {
    return mappingProvider;
}
 
Example 15
Source Project: bender   Source File: JsonPathProvider.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public MappingProvider mappingProvider() {
  return mappingProvider;
}
 
Example 16
Source Project: lucene-solr   Source File: PackageUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static Configuration jsonPathConfiguration() {
  MappingProvider provider = new JacksonMappingProvider();
  JsonProvider jsonProvider = new JacksonJsonProvider();
  Configuration c = Configuration.builder().jsonProvider(jsonProvider).mappingProvider(provider).options(com.jayway.jsonpath.Option.REQUIRE_PROPERTIES).build();
  return c;
}
 
Example 17
Source Project: sparql-generate   Source File: ITER_JSONListKeys.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public MappingProvider mappingProvider() {
    return mappingProvider;
}
 
Example 18
Source Project: sparql-generate   Source File: ITER_CBOR.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public MappingProvider mappingProvider() {
    return mappingProvider;
}
 
Example 19
Source Project: irontest   Source File: IronTestApplication.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(Bootstrap<IronTestConfiguration> bootstrap) {
    bootstrap.addCommand(new UpgradeCommand());

    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);
}
 
Example 20
public void init() {
	logger.info("init " + this);

	chrono=new Chrono();

	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 (hasNewVersion()||!fileSetJson.exists() || fileSetJson.length() == 0 || getBoolean(FORCE_RELOAD)) {
			logger.info("Downloading "+version + " datafile");
			URLTools.download(URL_JSON_ALL_SETS_ZIP, fileSetJsonTemp);
			FileTools.unZipIt(fileSetJsonTemp,fileSetJson);
			FileTools.saveFile(fversion,version);
			setProperty(FORCE_RELOAD, "false");
		}
		Chrono chr = new Chrono();
		chr.start();
		logger.debug(this + " : parsing db file");
		ctx = JsonPath.parse(fileSetJson);
		logger.debug(this + " : parsing OK in " + chr.stop()+"s");
		
	} catch (Exception e1) {
		logger.error(e1);
	}
}
 
Example 21
Source Project: metron   Source File: JSONMapParser.java    License: Apache License 2.0 4 votes vote down vote up
@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));
    }
  }
}
 
Example 22
@Override
public MappingProvider mappingProvider() {
  return mappingProvider;
}
 
Example 23
@Override
public MappingProvider mappingProvider() {
  return mappingProvider;
}