@Test(expected = IllegalArgumentException.class) public void testPutFromJsonRootNameMismatch() { final String json = "{\"REPLY\":{\"NESTED_REC\":{\"F8_FIELD\":567.123000}}}"; final Record record = mock(Record.class); when(record.getName()).thenReturn("NOT_REPLY"); RecordWriter.putFromJson(json, record); }
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);  }