@Test public void testDeeplyNestedArraysAndRecords2() throws IOException, MalformedRecordException { InputStream is = new FileInputStream("src/test/resources/xml/people_complex2.xml"); XMLRecordReader reader = new XMLRecordReader(is, getSchemaForComplexData2(), true, null, "CONTENT", dateFormat, timeFormat, timestampFormat, Mockito.mock(ComponentLog.class)); Record first = reader.nextRecord(); assertEquals("grandmother", first.getValue("ROLE")); assertEquals("1", first.getValue("ID")); assertEquals("Lisa", first.getValue("NAME")); Object[] gm_spouses = (Object[]) first.getValue("CHILDREN"); assertEquals(2, gm_spouses.length); Object[] gm_spouse1_parents = (Object[]) ((Record) gm_spouses[0]).getValue("CHILD"); assertEquals(2, gm_spouse1_parents.length); Record first_1_1 = (Record) gm_spouse1_parents[0]; assertEquals("mother", first_1_1.getValue("ROLE")); assertEquals("1-1", first_1_1.getValue("ID")); assertEquals("Anna", first_1_1.getValue("NAME")); Object[] gm_spouse1_parent1_first_husband = (Object[]) first_1_1.getValue("CHILDREN"); assertEquals(1, gm_spouse1_parent1_first_husband.length); Object[] gm_spouse1_parent1_children = (Object[])((Record) gm_spouse1_parent1_first_husband[0]).getValue("CHILD"); Record first_1_1_1 = (Record) gm_spouse1_parent1_children[0]; assertEquals("daughter", first_1_1_1.getValue("ROLE")); assertEquals("1-1-1", first_1_1_1.getValue("ID")); assertEquals("Selina", first_1_1_1.getValue("NAME")); Record first_1_1_2 = (Record) gm_spouse1_parent1_children[1]; assertEquals("son", first_1_1_2.getValue("ROLE")); assertEquals("1-1-2", first_1_1_2.getValue("ID")); assertEquals("Hans", first_1_1_2.getValue("NAME")); Record first_1_2 = (Record) gm_spouse1_parents[1]; assertEquals("mother", first_1_2.getValue("ROLE")); assertEquals("1-2", first_1_2.getValue("ID")); assertEquals("Catrina", first_1_2.getValue("NAME")); Object[] gm_spouse2_parents = (Object[]) ((Record) gm_spouses[1]).getValue("CHILD"); assertEquals(1, gm_spouse2_parents.length); Record second = reader.nextRecord(); Record second_2_1_1 = (Record)((Object[])((Record)((Object[])((Record)((Object[])((Record)((Object[]) second .getValue("CHILDREN"))[0]) .getValue("CHILD"))[0]) .getValue("CHILDREN"))[0]) .getValue("CHILD"))[0]; assertEquals("daughter", second_2_1_1.getValue("ROLE")); assertEquals("2-1-1", second_2_1_1.getValue("ID")); assertEquals("Selina3", second_2_1_1.getValue("NAME")); }
@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();  }