@Test public void testNestedRecordCoerceFalseDropFalse() throws IOException, MalformedRecordException { InputStream is = new FileInputStream("src/test/resources/xml/people_nested.xml"); RecordSchema schema = getSchemaWithNestedRecord(); XMLRecordReader reader = new XMLRecordReader(is, schema, true, null, "CONTENT", dateFormat, timeFormat, timestampFormat, Mockito.mock(ComponentLog.class)); Record first = reader.nextRecord(false, false); Object[] valuesFirstRecord = first.getValues(); Assert.assertArrayEquals(new Object[] {"Cleve Butler", "42", "USA"}, Arrays.copyOfRange(valuesFirstRecord, 0, valuesFirstRecord.length - 1)); assertEquals("P1", first.getAsString("ID")); Record nestedFirstRecord = (Record) first.getValue("ADDRESS"); Assert.assertEquals("Jersey City", nestedFirstRecord.getAsString("CITY")); Assert.assertEquals("292 West Street", nestedFirstRecord.getAsString("STREET")); Record second = reader.nextRecord(false, false); Object[] valuesSecondRecord = second.getValues(); Assert.assertArrayEquals(new Object[] {"Ainslie Fletcher", "33", "UK"}, Arrays.copyOfRange(valuesSecondRecord, 0, valuesSecondRecord.length - 1)); assertEquals("P2", second.getAsString("ID")); Record nestedSecondRecord = (Record) second.getValue("ADDRESS"); Assert.assertEquals("Seattle", nestedSecondRecord.getAsString("CITY")); Assert.assertEquals("123 6th St.", nestedSecondRecord.getAsString("STREET")); Record third = reader.nextRecord(false, false); Object[] valuesThirdRecord = third.getValues(); Assert.assertArrayEquals(new Object[] {"Amélie Bonfils", "74", "FR"}, Arrays.copyOfRange(valuesThirdRecord, 0, valuesThirdRecord.length - 1)); assertEquals("P3", third.getAsString("ID")); Record nestedThirdRecord = (Record) third.getValue("ADDRESS"); Assert.assertEquals("Los Angeles", nestedThirdRecord.getAsString("CITY")); Assert.assertEquals("44 Shirley Ave.", nestedThirdRecord.getAsString("STREET")); Record fourth = reader.nextRecord(false, false); Object[] valuesFourthRecord = fourth.getValues(); Assert.assertArrayEquals(new Object[] {"Elenora Scrivens", "16", "USA"}, Arrays.copyOfRange(valuesFourthRecord, 0, valuesFourthRecord.length - 1)); assertEquals("P4", fourth.getAsString("ID")); Record nestedFourthRecord = (Record) fourth.getValue("ADDRESS"); Assert.assertEquals("Columbus", nestedFourthRecord.getAsString("CITY")); Assert.assertEquals("70 Bowman St.", nestedFourthRecord.getAsString("STREET")); }
@Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } }
XMLRecordReader implements RecordReader { @Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } } }
XMLRecordReader implements RecordReader { @Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } } XMLRecordReader(InputStream in, RecordSchema schema, boolean isArray, String attributePrefix, String contentFieldName,
                           final String dateFormat, final String timeFormat, final String timestampFormat, final ComponentLog logger); }
XMLRecordReader implements RecordReader { @Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } } XMLRecordReader(InputStream in, RecordSchema schema, boolean isArray, String attributePrefix, String contentFieldName,
                           final String dateFormat, final String timeFormat, final String timestampFormat, final ComponentLog logger); @Override Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields); @Override RecordSchema getSchema(); @Override void close(); }
XMLRecordReader implements RecordReader { @Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } } XMLRecordReader(InputStream in, RecordSchema schema, boolean isArray, String attributePrefix, String contentFieldName,
                           final String dateFormat, final String timeFormat, final String timestampFormat, final ComponentLog logger); @Override Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields); @Override RecordSchema getSchema(); @Override void close();  }