Deal better with multiple contexts in live beans model parse for boot 2.0

This commit is contained in:
Kris De Volder
2018-01-18 10:10:52 -08:00
parent f0d36ba034
commit f5d7b444ff

View File

@@ -117,26 +117,22 @@ public class LiveBeansModel {
public LiveBeansModel parse(String json) throws Exception {
Builder model = LiveBeansModel.builder();
JSONObject mainObject = new JSONObject(json);
JSONObject beansObject = getBeans(mainObject);
for (String id : beansObject.keySet()) {
JSONObject beanObject = beansObject.getJSONObject(id);
LiveBean bean = parseBean(id, beanObject);
if (bean!=null) {
model.add(bean);
mainObject = mainObject.getJSONObject("contexts");
for (String contextId : mainObject.keySet()) {
JSONObject contextObject = mainObject.getJSONObject(contextId);
JSONObject beansObject = contextObject.getJSONObject("beans");
for (String id : beansObject.keySet()) {
JSONObject beanObject = beansObject.getJSONObject(id);
LiveBean bean = parseBean(id, contextId, beanObject);
if (bean!=null) {
model.add(bean);
}
}
}
return model.build();
}
private JSONObject getBeans(JSONObject mainObject) {
JSONObject beans = mainObject.optJSONObject("beans");
if (beans==null) {
beans = mainObject.getJSONObject("contexts").getJSONObject("application").getJSONObject("beans");
}
return beans;
}
private LiveBean parseBean(String id, JSONObject beansJSON) {
private LiveBean parseBean(String id, String contextId, JSONObject beansJSON) {
String type = beansJSON.optString("type");
String scope = beansJSON.optString("scope");
String resource = beansJSON.optString("resource");