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 1fce145
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 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 int depthToFlattenJsonArrays,
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.depthToFlattenJsonArrays = depthToFlattenJsonArrays;
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.depthToFlattenJsonArrays = 0;
this.hasLiteralsWithNumbers = false;
this.hasFallbacksForUnparsableNumbers = false;
this.defaultDouble = 0.0;
Expand Down Expand Up @@ -84,6 +87,17 @@ public Builder root(final String root) {
return this;
}

/**
* Sets the depth to flatten JSON Arrays to parse.
*
* @param depthToFlattenJsonArrays the depth to flatten JSON Arrays
* @return this builder
*/
public Builder setDepthToFlattenJsonArrays(final int depthToFlattenJsonArrays) {
this.depthToFlattenJsonArrays = depthToFlattenJsonArrays;
return this;
}

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

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

private final int depthToFlattenJsonArrays;
private final boolean hasLiteralsWithNumbers;
private final boolean hasFallbacksForUnparsableNumbers;
private final double defaultDouble;
Expand Down

0 comments on commit 1fce145

Please sign in to comment.