com.jayway.jsonpath.spi.mapper.GsonMappingProvider Java Examples

The following examples show how to use com.jayway.jsonpath.spi.mapper.GsonMappingProvider. 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 Project: micro-integrator   Author: wso2   File: EnrichIntegrationJsonPathTestCase.java    License: 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 Project: product-ei   Author: wso2   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 #3
Source Project: product-ei   Author: wso2   File: EnrichIntegrationJsonPathTestCase.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 #4
Source Project: carbon-apimgt   Author: wso2   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 #5
Source Project: ee8-sandbox   Author: hantsy   File: JsonbTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void personToJsonString() {
    Person duke = new Person("Duke", LocalDate.of(1995, 5, 23));
    duke.setPhoneNumbers(
            Arrays.asList(
                    new PhoneNumber(HOME, "100000"),
                    new PhoneNumber(OFFICE, "200000")
            )
    );

    Jsonb jsonMapper = JsonbBuilder.create();
    String json = jsonMapper.toJson(duke);

    LOG.log(Level.INFO, "converted json result: {0}", json);

    String name = JsonPath.parse(json).read("$.name");
    assertEquals("Duke", name);

    Configuration config = Configuration.defaultConfiguration()
            .jsonProvider(new GsonJsonProvider())
            .mappingProvider(new GsonMappingProvider());
    TypeRef<List<String>> typeRef = new TypeRef<List<String>>() {
    };

    List<String> numbers = JsonPath.using(config).parse(json).read("$.phoneNumbers[*].number", typeRef);

    assertEquals(Arrays.asList("100000", "200000"), numbers);
}
 
Example #6
Source Project: bdt   Author: Stratio   File: CommonG.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Remove a subelement in a JsonPath
 *
 * @param jsonString String of the json
 * @param expr       regex to be removed
 */

public String removeJSONPathElement(String jsonString, String expr) {

    Configuration conf = Configuration.builder().jsonProvider(new GsonJsonProvider()).mappingProvider(new GsonMappingProvider()).build();
    DocumentContext context = JsonPath.using(conf).parse(jsonString);
    context.delete(expr);
    return context.jsonString();
}
 
Example #7
Source Project: akita   Author: alfa-laboratory   File: BaseMethods.java    License: Apache License 2.0 4 votes vote down vote up
protected Configuration createJsonPathConfiguration() {
    return new Configuration.ConfigurationBuilder()
            .jsonProvider(new GsonJsonProvider())
            .mappingProvider(new GsonMappingProvider())
            .build();
}
 
Example #8
Source Project: MtgDesktopCompanion   Author: nicho92   File: Mtgjson4Provider.java    License: 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);
	}
}