Skip to content

Commit

Permalink
[WIP] Implement flattening JSON Arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikurube committed Aug 18, 2023
1 parent 8eba18b commit d91764c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/org/embulk/util/json/JsonValueParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
public final class JsonValueParser implements Closeable {
private JsonValueParser(
final com.fasterxml.jackson.core.JsonParser jacksonParser,
final boolean flattenJsonArray,
final boolean hasLiteralsWithNumbers,
final boolean hasFallbacksForUnparsableNumbers,
final double defaultDouble,
final long defaultLong) {
this.jacksonParser = Objects.requireNonNull(jacksonParser);
this.valueReader = new InternalJsonValueReader(
hasLiteralsWithNumbers, hasFallbacksForUnparsableNumbers, defaultDouble, defaultLong);
this.flattenJsonArray = flattenJsonArray;
this.hasLiteralsWithNumbers = hasLiteralsWithNumbers;
this.hasFallbacksForUnparsableNumbers = hasFallbacksForUnparsableNumbers;
this.defaultDouble = defaultDouble;
Expand All @@ -54,6 +56,7 @@ public static final class Builder {
Builder(final JsonFactory factory) {
this.factory = Objects.requireNonNull(factory);
this.root = null;
this.flattenJsonArray = false;
this.hasLiteralsWithNumbers = false;
this.hasFallbacksForUnparsableNumbers = false;
this.defaultDouble = 0.0;
Expand Down Expand Up @@ -84,6 +87,16 @@ public Builder root(final String root) {
return this;
}

/**
* Enables flattening JSON Arrays to parse.
*
* @return this builder
*/
public Builder flattenJsonArray() {
this.flattenJsonArray = true;
return this;
}

/**
* Enables creating {@link JsonDouble} and {@link JsonLong} instances with supplemental literal strings.
*
Expand Down Expand Up @@ -126,6 +139,7 @@ public Builder fallbackForUnparsableNumbers(final double defaultDouble, final lo
public JsonValueParser build(final String json) throws IOException {
return new JsonValueParser(
buildJacksonParser(json),
this.flattenJsonArray,
this.hasLiteralsWithNumbers,
this.hasFallbacksForUnparsableNumbers,
this.defaultDouble,
Expand All @@ -141,6 +155,7 @@ public JsonValueParser build(final String json) throws IOException {
public JsonValueParser build(final InputStream jsonStream) throws IOException {
return new JsonValueParser(
buildJacksonParser(jsonStream),
this.flattenJsonArray,
this.hasLiteralsWithNumbers,
this.hasFallbacksForUnparsableNumbers,
this.defaultDouble,
Expand Down Expand Up @@ -170,6 +185,7 @@ private com.fasterxml.jackson.core.JsonParser extendJacksonParser(final com.fast
private final JsonFactory factory;

private JsonPointer root;
private boolean flattenJsonArray;
private boolean hasLiteralsWithNumbers;
private boolean hasFallbacksForUnparsableNumbers;
private double defaultDouble;
Expand Down Expand Up @@ -243,6 +259,7 @@ public final void close() throws IOException {
private final com.fasterxml.jackson.core.JsonParser jacksonParser;
private final InternalJsonValueReader valueReader;

private final boolean flattenJsonArray;
private final boolean hasLiteralsWithNumbers;
private final boolean hasFallbacksForUnparsableNumbers;
private final double defaultDouble;
Expand Down

0 comments on commit d91764c

Please sign in to comment.