@Test public void testPutFromJsonDynamicList() { final String json = "{\"REPLY\":{\"VAR_LIST\":[{\"F8_FIELD\":987.654000},{\"F8_FIELD\":321.098000}]}}"; final Structure listStructure = mockStructure(F8_FIELD); final Field listField = mockField("VAR_LIST", DataType.DYNAMIC_LIST, listStructure); when(listField.getListSize()).thenReturn(Integer.valueOf(2)); final Record firstListElement = mockRecord("VAR_LIST", listStructure); final Record secondListElement = mockRecord("VAR_LIST", listStructure); final DynamicRecordList recordList = mock(DynamicRecordList.class); when(recordList.get(0)).thenReturn(firstListElement); when(recordList.get(1)).thenReturn(secondListElement); when(recordList.getSize()).thenReturn(Integer.valueOf(2)); final Structure recordStructure = mockStructure(listField); final Record record = mockRecord("REPLY", recordStructure); when(record.getDynamicList("VAR_LIST")).thenReturn(recordList); RecordWriter.putFromJson(json, record); verify(firstListElement, times(1)).setF8(F8_FIELD.getName(), 987.654); verify(secondListElement, times(1)).setF8(F8_FIELD.getName(), 321.098); }
public static void putFromJson(final String json, final Record record) { final JsonObject jsonObject = gson.fromJson(json, JsonObject.class); final String recordNameUpper = record.getName().toUpperCase(Locale.getDefault()); if (!jsonObject.has(recordNameUpper)) throw new IllegalArgumentException("JSON does not contain record " + recordNameUpper); putFromJsonObject(jsonObject.getAsJsonObject(recordNameUpper), record); }
RecordWriter { public static void putFromJson(final String json, final Record record) { final JsonObject jsonObject = gson.fromJson(json, JsonObject.class); final String recordNameUpper = record.getName().toUpperCase(Locale.getDefault()); if (!jsonObject.has(recordNameUpper)) throw new IllegalArgumentException("JSON does not contain record " + recordNameUpper); putFromJsonObject(jsonObject.getAsJsonObject(recordNameUpper), record); } }
RecordWriter { public static void putFromJson(final String json, final Record record) { final JsonObject jsonObject = gson.fromJson(json, JsonObject.class); final String recordNameUpper = record.getName().toUpperCase(Locale.getDefault()); if (!jsonObject.has(recordNameUpper)) throw new IllegalArgumentException("JSON does not contain record " + recordNameUpper); putFromJsonObject(jsonObject.getAsJsonObject(recordNameUpper), record); }  }
RecordWriter { public static void putFromJson(final String json, final Record record) { final JsonObject jsonObject = gson.fromJson(json, JsonObject.class); final String recordNameUpper = record.getName().toUpperCase(Locale.getDefault()); if (!jsonObject.has(recordNameUpper)) throw new IllegalArgumentException("JSON does not contain record " + recordNameUpper); putFromJsonObject(jsonObject.getAsJsonObject(recordNameUpper), record); }  static void putFromJson(final String json, final Record record); }
RecordWriter { public static void putFromJson(final String json, final Record record) { final JsonObject jsonObject = gson.fromJson(json, JsonObject.class); final String recordNameUpper = record.getName().toUpperCase(Locale.getDefault()); if (!jsonObject.has(recordNameUpper)) throw new IllegalArgumentException("JSON does not contain record " + recordNameUpper); putFromJsonObject(jsonObject.getAsJsonObject(recordNameUpper), record); }  static void putFromJson(final String json, final Record record);  }