From 6b552647da35d6bacf5ae84c9748b19c1c909adc Mon Sep 17 00:00:00 2001 From: Dai MIKURUBE Date: Fri, 22 Sep 2023 10:53:40 +0900 Subject: [PATCH] Guess with org.embulk.spi.json.JsonValue, instead of org.msgpack.value.Value --- embulk-guess-json/build.gradle | 3 +-- embulk-guess-json/gradle.lockfile | 2 +- .../embulk/guess/json/JsonGuessPlugin.java | 20 +++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/embulk-guess-json/build.gradle b/embulk-guess-json/build.gradle index 03a8a449d..8e5e82472 100644 --- a/embulk-guess-json/build.gradle +++ b/embulk-guess-json/build.gradle @@ -35,11 +35,10 @@ java { dependencies { compileOnly "org.embulk:embulk-spi:0.11" - compileOnly "org.msgpack:msgpack-core:0.8.24" implementation "org.embulk:embulk-util-config:0.3.4" implementation "org.embulk:embulk-util-file:0.1.5" - implementation "org.embulk:embulk-util-json:0.2.2" + implementation "org.embulk:embulk-util-json:0.3.0" } embulkPlugin { diff --git a/embulk-guess-json/gradle.lockfile b/embulk-guess-json/gradle.lockfile index 065a73e41..ddfd04029 100644 --- a/embulk-guess-json/gradle.lockfile +++ b/embulk-guess-json/gradle.lockfile @@ -9,7 +9,7 @@ javax.validation:validation-api:1.1.0.Final=compileClasspath,runtimeClasspath org.embulk:embulk-spi:0.11=compileClasspath org.embulk:embulk-util-config:0.3.4=compileClasspath,runtimeClasspath org.embulk:embulk-util-file:0.1.5=compileClasspath,runtimeClasspath -org.embulk:embulk-util-json:0.2.2=compileClasspath,runtimeClasspath +org.embulk:embulk-util-json:0.3.0=compileClasspath,runtimeClasspath org.msgpack:msgpack-core:0.8.24=compileClasspath org.slf4j:slf4j-api:2.0.7=compileClasspath empty= diff --git a/embulk-guess-json/src/main/java/org/embulk/guess/json/JsonGuessPlugin.java b/embulk-guess-json/src/main/java/org/embulk/guess/json/JsonGuessPlugin.java index b587a72c3..516683f0c 100644 --- a/embulk-guess-json/src/main/java/org/embulk/guess/json/JsonGuessPlugin.java +++ b/embulk-guess-json/src/main/java/org/embulk/guess/json/JsonGuessPlugin.java @@ -27,12 +27,12 @@ import org.embulk.spi.BufferAllocator; import org.embulk.spi.Exec; import org.embulk.spi.GuessPlugin; +import org.embulk.spi.json.JsonValue; import org.embulk.util.config.ConfigMapperFactory; import org.embulk.util.file.FileInputInputStream; import org.embulk.util.file.InputStreamFileInput; import org.embulk.util.json.JsonParseException; -import org.embulk.util.json.JsonParser; -import org.msgpack.value.Value; +import org.embulk.util.json.JsonValueParser; public class JsonGuessPlugin implements GuessPlugin { @Override @@ -45,17 +45,17 @@ public ConfigDiff guess(final ConfigSource config, final Buffer sample) { final BufferAllocator bufferAllocator = Exec.getBufferAllocator(); - // Use org.embulk.spi.json.JsonParser to respond to multi-line Json - final JsonParser.Stream jsonParser = newJsonParser(sample, bufferAllocator); + // Use org.embulk.util.json.JsonValueParser to respond to multi-line JSON + final JsonValueParser parser = newJsonParser(sample, bufferAllocator); boolean oneJsonParsed = false; try { - Value v = null; - while ((v = jsonParser.next()) != null) { - // "v" needs to be JSON object type (isMapValue) because: + JsonValue v = null; + while ((v = parser.readJsonValue()) != null) { + // "v" needs to be JSON object type (isJsonValue) because: // 1) Single-column CSV can be mis-guessed as JSON if JSON non-objects are accepted. // 2) JsonParserPlugin accepts only the JSON object type. - if (!v.isMapValue()) { + if (!v.isJsonObject()) { throw new JsonParseException("v must be JSON object type"); } oneJsonParsed = true; @@ -76,7 +76,7 @@ public ConfigDiff guess(final ConfigSource config, final Buffer sample) { return configDiff; } - private static JsonParser.Stream newJsonParser(final Buffer buffer, final BufferAllocator bufferAllocator) { + private static JsonValueParser newJsonParser(final Buffer buffer, final BufferAllocator bufferAllocator) { final ArrayList inputStreams = new ArrayList<>(); inputStreams.add(buildByteArrayInputStream(buffer)); @@ -85,7 +85,7 @@ private static JsonParser.Stream newJsonParser(final Buffer buffer, final Buffer final FileInputInputStream input = new FileInputInputStream(new InputStreamFileInput(bufferAllocator, iteratorProvider)); input.nextFile(); try { - return (new JsonParser()).open(input); + return JsonValueParser.builder().build(input); } catch (final IOException ex) { throw new UncheckedIOException(ex); }