| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public DDF serialize2DDF(DDFManager manager) throws DDFException { |
| 135 | String json = this.toJson(); |
| 136 | |
| 137 | Gson gson = new Gson(); |
| 138 | Map<String, Object> keyValueMap = gson.fromJson(json, Map.class); |
| 139 | JsonObject jsonObject = (new JsonParser().parse(json)).getAsJsonObject(); |
| 140 | |
| 141 | Set<String> keyset = keyValueMap.keySet(); |
| 142 | Iterator<String> keys = keyset.iterator(); |
| 143 | List<String> listColumns = new ArrayList<String>(); |
| 144 | List<String> listValues = new ArrayList<String>(); |
| 145 | |
| 146 | while (keys.hasNext()) { |
| 147 | String key = keys.next(); |
| 148 | String value = jsonObject.get(key).toString(); |
| 149 | listColumns.add(String.format(("%s string"), key)); |
| 150 | listValues.add(value); |
| 151 | } |
| 152 | |
| 153 | // Create schema for DDF |
| 154 | String columns = StringUtils.join(listColumns, ", "); |
| 155 | |
| 156 | Schema schema = new Schema(this.getName(), columns); |
| 157 | |
| 158 | return new BasicDDF(manager, listValues, String.class, manager |
| 159 | .getNamespace(), this.getName(), schema); |
| 160 | } |
| 161 | |
| 162 | public static Model deserializeFromDDF(BasicDDF ddf) throws DDFException { |
| 163 | List<String> data = ddf.getList(String.class); |