@Test public void testPutFromJsonDeepSimpleList() { final String json = "{\"REPLY\":{\"FIXED_LIST\":[{\"F8_FIELD\":123.456000},{\"F8_FIELD\":789.0120000}]}}"; final Structure listStructure = mockStructure(F8_FIELD); final Field listField = mockField("FIXED_LIST", DataType.LIST, listStructure); when(listField.getListSize()).thenReturn(Integer.valueOf(1)); final Record firstListElement = mockRecord("FIXED_LIST", listStructure); final Record secondListElement = mockRecord("FIXED_LIST", listStructure); final RecordList recordList = mock(RecordList.class); when(recordList.iterator()).thenReturn(Arrays.asList(firstListElement, secondListElement).iterator()); when(recordList.getSize()).thenReturn(Integer.valueOf(2)); final Structure recordStructure = mockStructure(listField); final Record record = mockRecord("REPLY", recordStructure); when(record.getList("FIXED_LIST")).thenReturn(recordList); RecordWriter.putFromJson(json, record); verify(firstListElement, times(1)).setF8(F8_FIELD.getName(), 123.456); verify(secondListElement, times(1)).setF8(F8_FIELD.getName(), 789.012); }
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);  }