本文整理汇总了Java中org.springframework.boot.json.JsonParser.parseMap方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParser.parseMap方法的具体用法?Java JsonParser.parseMap怎么用?Java JsonParser.parseMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.boot.json.JsonParser
的用法示例。
在下文中一共展示了JsonParser.parseMap方法的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);
}
示例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;
}
示例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());
// }
}
示例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);
}
示例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