当前位置: 首页>>代码示例>>Java>>正文


Java JsonParser类代码示例

本文整理汇总了Java中org.springframework.boot.json.JsonParser的典型用法代码示例。如果您正苦于以下问题:Java JsonParser类的具体用法?Java JsonParser怎么用?Java JsonParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JsonParser类属于org.springframework.boot.json包,在下文中一共展示了JsonParser类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadHomeDirectory

import org.springframework.boot.json.JsonParser; //导入依赖的package包/类
/**
 * Look up in the home directory for the corresponding
 * reporting configuration.
 */
public void loadHomeDirectory(){
    homeFolder = System.getProperty(ENV_HOME_FOLDER);
    if(homeFolder == null)
        throw new RuntimeException("The reports.home env variable should be specified at start up");

    Path reportsHome = Paths.get(homeFolder);
    Path mainConfig = reportsHome.resolve(MAIN_CONFIG_FILE_NAME);

    if(!Files.exists(mainConfig))
        throw new RuntimeException("There is no '"+MAIN_CONFIG_FILE_NAME+"' inside the home folder");

    JsonParser jsonParser = new BasicJsonParser();
    Map<String, Object> jsonMap = null;

    try {
        jsonMap = jsonParser.parseMap(new String(Files.readAllBytes(mainConfig)));
    } catch (IOException e) {
        throw new RuntimeException("Filed to read the '"+MAIN_CONFIG_FILE_NAME+"' file", e);
    }

    reports = (List<String>)jsonMap.get(MAIN_CONFIG_REPORTS_PROPERTY);
}
 
开发者ID:Ohtar10,项目名称:jrepman,代码行数:27,代码来源:ConfLoader.java

示例2: pubSubCloud

import org.springframework.boot.json.JsonParser; //导入依赖的package包/类
@Bean
@Profile("cloud")
public PubSub pubSubCloud(Environment environment) throws Exception {
	String vcapServicesEnv = environment.getProperty("VCAP_SERVICES");
	JsonParser parser = JsonParserFactory.getJsonParser();
	Map<String, Object> services = parser.parseMap(vcapServicesEnv);
	List<Map<String, Object>> googlePubsub = (List<Map<String, Object>>) services.get("google-pubsub");
	Map<String, Object> credentials = (Map<String, Object>) googlePubsub.get(0).get("credentials");
	String privateKeyData = (String) credentials.get("PrivateKeyData");
	GoogleCredential googleCredential = GoogleCredential.fromStream(new ByteArrayInputStream(Base64.decodeBase64(privateKeyData)));

	return PubSubOptions.newBuilder().setAuthCredentials(AuthCredentials.createFor(googleCredential.getServiceAccountId(),
			googleCredential.getServiceAccountPrivateKey()))
			.setProjectId(pubSubBinderConfigurationProperties.getProjectName()).build().getService();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-google-pubsub,代码行数:16,代码来源:PubSubServiceAutoConfiguration.java

示例3: loadReportDefinition

import org.springframework.boot.json.JsonParser; //导入依赖的package包/类
/**
 * Based on the definition found in the given path,
 * creates a new instance of ReportDefinition.
 * @param reportPath path where the report source lies
 * @return Report Definition instance
 */
public ReportDefinition loadReportDefinition(String reportPath){
    Path reportDefinitionFile = Paths.get(reportPath).resolve("report.json");

    JsonParser jsonParser = new BasicJsonParser();
    Map<String, Object> jsonMap = null;

    try {
        jsonMap = jsonParser.parseMap(new String(Files.readAllBytes(reportDefinitionFile)));
    } catch (IOException e) {
        throw new RuntimeException("Failed to read the '"+reportDefinitionFile+"' file", e);
    }

    ReportDefinition reportDefinition = new ReportDefinition();
    Map<String, ReportParamDataType> params = new HashMap<>();
    reportDefinition.setName(jsonMap.get(ReportDefinitionProperties.NAME.getName()).toString());
    reportDefinition.setReportFile(jsonMap.get(ReportDefinitionProperties.REPORT_FILE.getName()).toString());
    reportDefinition.setReportPath(Paths.get(reportPath));
    reportDefinition.setParams(params);

    Map<String, String> rawParams = (Map<String, String>)jsonMap.get(ReportDefinitionProperties.PARAMS.getName());


    Set<Map.Entry<String, String>> entrySet = rawParams.entrySet();
    for(Map.Entry<String, String> entry: entrySet){
        params.put(entry.getKey(), ReportParamDataType.fromKey(entry.getValue()));
    }


    return reportDefinition;
}
 
开发者ID:Ohtar10,项目名称:jrepman,代码行数:37,代码来源:ReportLoader.java

示例4: Json2MapReader

import org.springframework.boot.json.JsonParser; //导入依赖的package包/类
public Json2MapReader(String json)
{
  JsonParser parser = JsonParserFactory.getJsonParser();
  map = parser.parseMap(json);
  // For creating test files:
  // try {
  // FileWriter writer = new FileWriter(new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss.SSS").format(new Date()) + "-json.txt");
  // writer.append(json);
  // writer.close();
  // } catch (IOException e) {
  // System.out.println(e.getMessage());
  // }
}
 
开发者ID:kreinhard,项目名称:OpenViSu,代码行数:14,代码来源:Json2MapReader.java

示例5: processJson

import org.springframework.boot.json.JsonParser; //导入依赖的package包/类
private void processJson(ConfigurableEnvironment environment, String json) {
	try {
		JsonParser parser = JsonParserFactory.getJsonParser();
		Map<String, Object> map = parser.parseMap(json);
		if (!map.isEmpty()) {
			addJsonPropertySource(environment,
					new MapPropertySource("spring.application.json", flatten(map)));
		}
	}
	catch (Exception ex) {
		logger.warn("Cannot parse JSON for spring.application.json: " + json, ex);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:SpringApplicationJsonEnvironmentPostProcessor.java

示例6: setCredentialsJson

import org.springframework.boot.json.JsonParser; //导入依赖的package包/类
public void setCredentialsJson(String credentialsJson) {
    JsonParser parser = JsonParserFactory.getJsonParser();
    this.credentialsJson = parser.parseMap(credentialsJson);
}
 
开发者ID:orange-cloudfoundry,项目名称:static-creds-broker,代码行数:5,代码来源:PlanProperties.java

示例7: getJsonMapFromEnvironment

import org.springframework.boot.json.JsonParser; //导入依赖的package包/类
private Map<String, Object> getJsonMapFromEnvironment() {
    JsonParser jsonParser = JsonParserFactory.getJsonParser();
    Map<String, Object> jsonMap;
    jsonMap = jsonParser.parseMap(getVCapVariable());
    return (Map<String, Object>) ((List<Map<String, Object>>) jsonMap.get( "p-cassandra")).get(0).get("credentials");
}
 
开发者ID:pivotal-cf,项目名称:cf-cassandra-spring-example-app,代码行数:7,代码来源:CloudCassandraPropertiesManager.java


注:本文中的org.springframework.boot.json.JsonParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。