@Test public void testFlattenJsonOnNestedJsonHavingListWithoutGivingParentPath() throws Exception { TargetModel target = new HdfsTargetModel("test4", hdfsExplorer); List<DataRecord> result = JsonAdapter.flattenJson(dataRecord, nestedJsonHavingList, target); List<Map<String, String>> expectedColumnsList = new ArrayList<>(); Map<String, String> commonColumnValuesMap = new HashMap<>(); commonColumnValuesMap.put("fp", "2017-09"); commonColumnValuesMap.put("SR1", "Y"); expectedColumnsList.add(commonColumnValuesMap); Assert.assertTrue(compareResult(result, expectedColumnsList)); }
public static List<DataRecord> flattenJson(DataRecord dataRecord, String json, TargetModel targetModel) throws InvalidJSONException, ColumnFamilyNotFoundException, InvalidColumnException { List<DataRecord> dataRecordList = new ArrayList<>(); dataRecordList.add(dataRecord); boolean useParentKey = true; JsonElement jsonElement = parser.parse(json); if (jsonElement instanceof JsonObject) { return flattenJson(dataRecordList, (JsonObject) jsonElement, useParentKey, null, targetModel) .getDataRecordList(); } else if (jsonElement instanceof JsonArray) { List<DataRecord> finalDataRecordList = new ArrayList<>(); for (JsonElement jsonElement1 : jsonElement.getAsJsonArray()) { finalDataRecordList.addAll(flattenJson(dataRecord, jsonElement1.toString(), targetModel)); } return finalDataRecordList; } else { throw new InvalidJSONException("Expected a JsonObject, but found " + jsonElement.getClass()); } }
JsonAdapter { public static List<DataRecord> flattenJson(DataRecord dataRecord, String json, TargetModel targetModel) throws InvalidJSONException, ColumnFamilyNotFoundException, InvalidColumnException { List<DataRecord> dataRecordList = new ArrayList<>(); dataRecordList.add(dataRecord); boolean useParentKey = true; JsonElement jsonElement = parser.parse(json); if (jsonElement instanceof JsonObject) { return flattenJson(dataRecordList, (JsonObject) jsonElement, useParentKey, null, targetModel) .getDataRecordList(); } else if (jsonElement instanceof JsonArray) { List<DataRecord> finalDataRecordList = new ArrayList<>(); for (JsonElement jsonElement1 : jsonElement.getAsJsonArray()) { finalDataRecordList.addAll(flattenJson(dataRecord, jsonElement1.toString(), targetModel)); } return finalDataRecordList; } else { throw new InvalidJSONException("Expected a JsonObject, but found " + jsonElement.getClass()); } } }
JsonAdapter { public static List<DataRecord> flattenJson(DataRecord dataRecord, String json, TargetModel targetModel) throws InvalidJSONException, ColumnFamilyNotFoundException, InvalidColumnException { List<DataRecord> dataRecordList = new ArrayList<>(); dataRecordList.add(dataRecord); boolean useParentKey = true; JsonElement jsonElement = parser.parse(json); if (jsonElement instanceof JsonObject) { return flattenJson(dataRecordList, (JsonObject) jsonElement, useParentKey, null, targetModel) .getDataRecordList(); } else if (jsonElement instanceof JsonArray) { List<DataRecord> finalDataRecordList = new ArrayList<>(); for (JsonElement jsonElement1 : jsonElement.getAsJsonArray()) { finalDataRecordList.addAll(flattenJson(dataRecord, jsonElement1.toString(), targetModel)); } return finalDataRecordList; } else { throw new InvalidJSONException("Expected a JsonObject, but found " + jsonElement.getClass()); } }  }
JsonAdapter { public static List<DataRecord> flattenJson(DataRecord dataRecord, String json, TargetModel targetModel) throws InvalidJSONException, ColumnFamilyNotFoundException, InvalidColumnException { List<DataRecord> dataRecordList = new ArrayList<>(); dataRecordList.add(dataRecord); boolean useParentKey = true; JsonElement jsonElement = parser.parse(json); if (jsonElement instanceof JsonObject) { return flattenJson(dataRecordList, (JsonObject) jsonElement, useParentKey, null, targetModel) .getDataRecordList(); } else if (jsonElement instanceof JsonArray) { List<DataRecord> finalDataRecordList = new ArrayList<>(); for (JsonElement jsonElement1 : jsonElement.getAsJsonArray()) { finalDataRecordList.addAll(flattenJson(dataRecord, jsonElement1.toString(), targetModel)); } return finalDataRecordList; } else { throw new InvalidJSONException("Expected a JsonObject, but found " + jsonElement.getClass()); } }  static List<DataRecord> flattenJson(DataRecord dataRecord, String json, TargetModel targetModel); }
JsonAdapter { public static List<DataRecord> flattenJson(DataRecord dataRecord, String json, TargetModel targetModel) throws InvalidJSONException, ColumnFamilyNotFoundException, InvalidColumnException { List<DataRecord> dataRecordList = new ArrayList<>(); dataRecordList.add(dataRecord); boolean useParentKey = true; JsonElement jsonElement = parser.parse(json); if (jsonElement instanceof JsonObject) { return flattenJson(dataRecordList, (JsonObject) jsonElement, useParentKey, null, targetModel) .getDataRecordList(); } else if (jsonElement instanceof JsonArray) { List<DataRecord> finalDataRecordList = new ArrayList<>(); for (JsonElement jsonElement1 : jsonElement.getAsJsonArray()) { finalDataRecordList.addAll(flattenJson(dataRecord, jsonElement1.toString(), targetModel)); } return finalDataRecordList; } else { throw new InvalidJSONException("Expected a JsonObject, but found " + jsonElement.getClass()); } }  static List<DataRecord> flattenJson(DataRecord dataRecord, String json, TargetModel targetModel);  }