public class JsonArraySplitter extends JsonSplitter
JsonSplitter
that splits a json array that is one of the root fields of the document
into json object nodes.
It also takes a list of fields to "extract" from the root fields of the document besides the actual list of documents to be splitted, this is normally a "next page token" or similar.
If the json has more than one field with the name of the searched array, only first will be taken in account, the followings fields will be ignored.
This class must be closed in order to free underlying resources.
Constructor and Description |
---|
JsonArraySplitter(InputStream inputStream,
String arrayFieldName)
Creates a new instance that will search for an array field at the root named arrayFieldName to split.
|
JsonArraySplitter(InputStream inputStream,
String arrayFieldName,
boolean failIfArrayFieldNotFound,
Set<String> fieldNamesSet,
PayloadMetadata metadata)
Creates a new instance that will search for an array field at the root named arrayFieldName to split and also try
to extract all the fields in fieldNamesSet.
|
JsonArraySplitter(InputStream inputStream,
String arrayFieldName,
PayloadMetadata metadata)
Creates a new instance that will search for an array field at the root named arrayFieldName to split.
|
JsonArraySplitter(InputStream inputStream,
String arrayFieldName,
Set<String> fieldNamesSet)
Creates a new instance that will search for an array field at the root named arrayFieldName to split and also try
to extract all the fields in fieldNamesSet.
|
JsonArraySplitter(InputStream inputStream,
String arrayFieldName,
Set<String> fieldNamesSet,
PayloadMetadata metadata)
Creates a new instance that will search for an array field at the root named arrayFieldName to split and also try
to extract all the fields in fieldNamesSet.
|
Modifier and Type | Method and Description |
---|---|
protected JsonToken |
findNextNodeStart() |
JsonNode |
getFieldFoundValue(String fieldName)
Gets the value of a field that was extracted from the document.
|
Map<String,JsonNode> |
getFieldsFound()
Gets a map with all the fields that were extracted from the document.
|
protected void |
initialize() |
boolean |
wasFieldFound(String fieldName)
Validates if a given field was extracted from the document.
|
close, createGenerator, getParser, iterator, waitForToken, waitForTokens
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public JsonArraySplitter(InputStream inputStream, String arrayFieldName) throws IOException
inputStream
- stream that contains the JSON documentarrayFieldName
- name of the field at the root that contains the array to splitIOException
- if there's a problem processing the inputStreampublic JsonArraySplitter(InputStream inputStream, String arrayFieldName, PayloadMetadata metadata) throws IOException
inputStream
- stream that contains the JSON documentarrayFieldName
- name of the field at the root that contains the array to splitmetadata
- include metadata for all the resulting payloadsIOException
- if there's a problem processing the inputStreampublic JsonArraySplitter(InputStream inputStream, String arrayFieldName, Set<String> fieldNamesSet) throws IOException
inputStream
- stream that contains the JSON documentarrayFieldName
- name of the field at the root that contains the array to splitfieldNamesSet
- Set
of fields at the root to extract from the JSON documentIOException
- if there's a problem processing the inputStreampublic JsonArraySplitter(InputStream inputStream, String arrayFieldName, Set<String> fieldNamesSet, PayloadMetadata metadata) throws IOException
inputStream
- stream that contains the JSON documentarrayFieldName
- name of the field at the root that contains the array to splitfieldNamesSet
- Set
of fields at the root to extract from the JSON documentmetadata
- include metadata for all the resulting payloadsIOException
- if there's a problem processing the inputStreampublic JsonArraySplitter(InputStream inputStream, String arrayFieldName, boolean failIfArrayFieldNotFound, Set<String> fieldNamesSet, PayloadMetadata metadata) throws IOException
inputStream
- stream that contains the JSON documentarrayFieldName
- name of the array field at the root that contains the array to splitfailIfArrayFieldNotFound
- When arrayFieldName is not found; if true an exception will be thrown. If false the rest of the fields
will be processed and no splitting will be done.fieldNamesSet
- Set
of fields at the root to extract from the JSON documentmetadata
- include metadata for all the resulting payloadsIOException
- if there's a problem processing the inputStreampublic boolean wasFieldFound(String fieldName)
The elements must be fully iterated to ensure that the field is found.
fieldName
- name of a field that was possibly extracted from the documentpublic JsonNode getFieldFoundValue(String fieldName)
The elements must be fully iterated to ensure that the field is found.
fieldName
- name of a field that was possibly extracted from the documentpublic Map<String,JsonNode> getFieldsFound()
The elements must be fully iterated to ensure that all the fields are found.
protected void initialize() throws IOException
initialize
in class JsonSplitter
IOException
protected JsonToken findNextNodeStart() throws IOException
findNextNodeStart
in class JsonSplitter
IOException