@Test public void testTagInCharactersCoerceFalseDropFalse() throws IOException, MalformedRecordException { InputStream is = new FileInputStream("src/test/resources/xml/people_tag_in_characters.xml"); XMLRecordReader reader = new XMLRecordReader(is, getSimpleSchema(), true, null, "CONTENT", dateFormat, timeFormat, timestampFormat, Mockito.mock(ComponentLog.class)); Record first = reader.nextRecord(false, false); assertEquals("P1", first.getValue("ID")); assertEquals("42", first.getValue("AGE")); Record firstNested = (Record) first.getValue("NAME"); assertEquals("Cleve Butler", firstNested.getValue("CONTENT")); assertEquals("attr content", firstNested.getValue("ATTR")); assertEquals("inner content", firstNested.getValue("INNER")); Record second = reader.nextRecord(false, false); assertEquals("P2", second.getValue("ID")); assertEquals("33", second.getValue("AGE")); Record secondNested = (Record) second.getValue("NAME"); assertEquals("Ainslie Fletcher", secondNested.getValue("CONTENT")); assertEquals("attr content", secondNested.getValue("ATTR")); assertEquals("inner content", secondNested.getValue("INNER")); Record third = reader.nextRecord(false, false); assertEquals("P3", third.getValue("ID")); assertEquals("74", third.getValue("AGE")); Record thirdNested = (Record) third.getValue("NAME"); assertEquals("Amélie Bonfils", thirdNested.getValue("CONTENT")); assertEquals("attr content", thirdNested.getValue("ATTR")); assertEquals("inner content", thirdNested.getValue("INNER")); Record fourth = reader.nextRecord(false, false); assertEquals("P4", fourth.getValue("ID")); assertEquals("16", fourth.getValue("AGE")); Record fourthNested = (Record) fourth.getValue("NAME"); assertEquals("Elenora Scrivens", fourthNested.getValue("CONTENT")); assertEquals("attr content", fourthNested.getValue("ATTR")); assertEquals("inner content", fourthNested.getValue("INNER")); Record fifth = reader.nextRecord(false, false); assertEquals("P5", fifth.getValue("ID")); assertNull(fifth.getValue("AGE")); Record fifthNested = (Record) fifth.getValue("NAME"); assertNull(fifthNested.getValue("CONTENT")); assertNull(fifthNested.getValue("ATTR")); assertEquals("inner content", fifthNested.getValue("INNER")); }
@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();  }