@Test public void testPutFromJsonRecord() { final String json = "{\"REPLY\":{\"NESTED_REC\":{\"F8_FIELD\":567.123000}}}"; final Structure nestedStructure = mockStructure(F8_FIELD); final Field nestedField = mockField("NESTED_REC", DataType.RECORD, nestedStructure); final Record nestedRecord = mockRecord("NESTED_REC", nestedStructure); final Structure rootStructure = mockStructure(nestedField); final Record rootRecord = mockRecord("REPLY", rootStructure); when(rootRecord.getRecord("NESTED_REC")).thenReturn(nestedRecord); RecordWriter.putFromJson(json, rootRecord); verify(nestedRecord, times(1)).setF8(F8_FIELD.getName(), 567.123); }
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);  }