com.jayway.jsonpath.spi.json.JsonProvider Java Examples

The following examples show how to use com.jayway.jsonpath.spi.json.JsonProvider. 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
Source File: EnrichIntegrationJsonPathTestCase.java    From micro-integrator with Apache License 2.0 7 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 #2
Source File: ForEachnativeJSONTestCase.java    From product-ei with 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 #3
Source File: JsonPathStartupHookProvider.java    From light-4j with 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 #4
Source File: MaskTest.java    From light-4j with 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 #5
Source File: TestCaseLoaderTest.java    From interface-test with 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 #6
Source File: InterfaceTestApplication.java    From interface-test with 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 #7
Source File: EnrichIntegrationJsonPathTestCase.java    From product-ei with 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
Source File: CloudFoundryAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: FieldLevelEncryption.java    From client-encryption-java with MIT License 6 votes vote down vote up
private static void addDecryptedDataToPayload(DocumentContext payloadContext, String decryptedValue, String jsonPathOut) {
    JsonProvider jsonProvider = jsonPathConfig.jsonProvider();
    Object decryptedValueJsonElement = jsonEngine.parse(decryptedValue);

    if (!jsonEngine.isJsonObject(decryptedValueJsonElement)) {
        // Array or primitive: overwrite
        payloadContext.set(jsonPathOut, decryptedValueJsonElement);
        return;
    }

    // Object: merge
    int length = jsonProvider.length(decryptedValueJsonElement);
    Collection<String> propertyKeys = (0 == length) ? Collections.<String>emptyList() : jsonProvider.getPropertyKeys(decryptedValueJsonElement);
    for (String key : propertyKeys) {
        payloadContext.delete(jsonPathOut + "." + key);
        payloadContext.put(jsonPathOut, key, jsonProvider.getMapValue(decryptedValueJsonElement, key));
    }
}
 
Example #10
Source File: TestSchemaValidator.java    From carbon-apimgt with 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 #11
Source File: LightServer.java    From light with 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 #12
Source File: FieldLevelEncryption.java    From client-encryption-java with MIT License 5 votes vote down vote up
private static Object readAndDeleteJsonKey(DocumentContext context, String objectPath, Object object, String key) {
    if (null == key) {
        // Do nothing
        return null;
    }
    JsonProvider jsonProvider = jsonPathConfig.jsonProvider();
    Object value = jsonProvider.getMapValue(object, key);
    context.delete(objectPath + "." + key);
    return value;
}
 
Example #13
Source File: NashornTest.java    From interface-test with 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 #14
Source File: ITER_CBOR.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
@Override
public JsonProvider jsonProvider() {
    return jsonProvider;
}
 
Example #15
Source File: IronTestApplication.java    From irontest with 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 #16
Source File: Mtgjson4Provider.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
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 #17
Source File: ITER_JSONListKeys.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
@Override
public JsonProvider jsonProvider() {
    return jsonProvider;
}
 
Example #18
Source File: JSONMapParser.java    From metron with 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 #19
Source File: JsonService.java    From cs-actions with Apache License 2.0 4 votes vote down vote up
private void parseJsonForInconsistencies(String normalizedJson) {
    JsonProvider provider = new GsonJsonProvider();
    Configuration configuration = Configuration.builder().jsonProvider(provider).build();
    JsonPath.parse(normalizedJson, configuration);       //throws an exception at runtime if the json is malformed
}
 
Example #20
Source File: JsonExtractKeyTransformFunction.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
@Override
public JsonProvider jsonProvider() {
  return jsonProvider;
}
 
Example #21
Source File: JsonExtractScalarTransformFunction.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
@Override
public JsonProvider jsonProvider() {
  return jsonProvider;
}
 
Example #22
Source File: PackageUtils.java    From lucene-solr with 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 #23
Source File: JsonPathProvider.java    From bender with Apache License 2.0 4 votes vote down vote up
@Override
public JsonProvider jsonProvider() {
  return jsonProvider;
}
 
Example #24
Source File: JsonUtils.java    From karate with MIT License 4 votes vote down vote up
@Override
public JsonProvider jsonProvider() {
    return jsonProvider;
}
 
Example #25
Source File: Jackson.java    From centraldogma with Apache License 2.0 4 votes vote down vote up
@Override
public JsonProvider jsonProvider() {
    return jsonPathCfg.jsonProvider();
}
 
Example #26
Source File: FieldLevelEncryption.java    From client-encryption-java with MIT License 4 votes vote down vote up
private static void decryptPayloadPath(DocumentContext payloadContext, String jsonPathIn, String jsonPathOut,
                                       FieldLevelEncryptionConfig config, FieldLevelEncryptionParams params) throws GeneralSecurityException, EncryptionException {

    JsonProvider jsonProvider = jsonPathConfig.jsonProvider();
    Object inJsonObject = readJsonObject(payloadContext, jsonPathIn);
    if (inJsonObject == null) {
        // Nothing to decrypt
        return;
    }

    // Read and remove encrypted data and encryption fields at the given JSON path
    Object encryptedValueJsonElement = readAndDeleteJsonKey(payloadContext, jsonPathIn, inJsonObject, config.encryptedValueFieldName);
    if (jsonEngine.isNullOrEmptyJson(encryptedValueJsonElement)) {
        // Nothing to decrypt
        return;
    }

    if (!config.useHttpPayloads() && params == null) {
        throw new IllegalStateException("Encryption params have to be set when not stored in HTTP payloads!");
    }

    if (params == null) {
        // Read encryption params from the payload
        Object oaepDigestAlgorithmJsonElement = readAndDeleteJsonKey(payloadContext, jsonPathIn, inJsonObject, config.oaepPaddingDigestAlgorithmFieldName);
        String oaepDigestAlgorithm = jsonEngine.isNullOrEmptyJson(oaepDigestAlgorithmJsonElement) ? config.oaepPaddingDigestAlgorithm : jsonEngine.toJsonString(oaepDigestAlgorithmJsonElement);
        Object encryptedKeyJsonElement = readAndDeleteJsonKey(payloadContext, jsonPathIn, inJsonObject, config.encryptedKeyFieldName);
        Object ivJsonElement = readAndDeleteJsonKey(payloadContext, jsonPathIn, inJsonObject, config.ivFieldName);
        readAndDeleteJsonKey(payloadContext, jsonPathIn, inJsonObject, config.encryptionCertificateFingerprintFieldName);
        readAndDeleteJsonKey(payloadContext, jsonPathIn, inJsonObject, config.encryptionKeyFingerprintFieldName);
        params = new FieldLevelEncryptionParams(jsonEngine.toJsonString(ivJsonElement), jsonEngine.toJsonString(encryptedKeyJsonElement), oaepDigestAlgorithm, config);
    }

    // Decrypt data
    byte[] encryptedValueBytes = decodeValue(jsonEngine.toJsonString(encryptedValueJsonElement), config.fieldValueEncoding);
    byte[] decryptedValueBytes = decryptBytes(params.getSecretKey(), params.getIvSpec(), encryptedValueBytes);

    // Add decrypted data at the given JSON path
    String decryptedValue = new String(decryptedValueBytes, StandardCharsets.UTF_8);
    decryptedValue = sanitizeJson(decryptedValue);
    checkOrCreateOutObject(payloadContext, jsonPathOut);
    addDecryptedDataToPayload(payloadContext, decryptedValue, jsonPathOut);

    // Remove the input if now empty
    Object inJsonElement  = readJsonElement(payloadContext, jsonPathIn);
    if (0 == jsonProvider.length(inJsonElement) && !"$".equals(jsonPathIn)) {
        payloadContext.delete(jsonPathIn);
    }
}
 
Example #27
Source File: JacksonJsonEngine.java    From client-encryption-java with MIT License 4 votes vote down vote up
@Override
public JsonProvider getJsonProvider() {
    return jsonProvider;
}
 
Example #28
Source File: JettisonJsonEngine.java    From client-encryption-java with MIT License 4 votes vote down vote up
@Override
public JsonProvider getJsonProvider() {
    return jsonProvider;
}
 
Example #29
Source File: JsonEngine.java    From client-encryption-java with MIT License 4 votes vote down vote up
protected boolean isJsonPrimitive(Object jsonElement) {
    JsonProvider jsonProvider = getJsonProvider();
    return !jsonProvider.isMap(jsonElement) && !jsonProvider.isArray(jsonElement);
}
 
Example #30
Source File: JsonSmartJsonEngine.java    From client-encryption-java with MIT License 4 votes vote down vote up
@Override
public JsonProvider getJsonProvider() {
    return jsonProvider;
}