From 204e5fe2fc36588c5c658af672288eeab4c62996 Mon Sep 17 00:00:00 2001 From: Dai MIKURUBE Date: Fri, 22 Sep 2023 11:14:22 +0900 Subject: [PATCH] Use org.embulk.spi.json.JsonValue, instead of org.msgpack.value.Value --- build.gradle | 10 +++++----- gradle.lockfile | 2 +- .../java/org/embulk/parser/csv/CsvParserPlugin.java | 12 ++++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 3ebf5fa88..17254d9a7 100644 --- a/build.gradle +++ b/build.gradle @@ -43,15 +43,15 @@ dependencies { implementation "org.embulk:embulk-util-csv:0.2.3" 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" implementation "org.embulk:embulk-util-text:0.1.3" implementation "org.embulk:embulk-util-timestamp:0.2.2" testImplementation "junit:junit:4.13.2" - testImplementation "org.embulk:embulk-spi:0.10.50" - testImplementation "org.embulk:embulk-core:0.10.50" - testImplementation "org.embulk:embulk-deps:0.10.50" - testImplementation "org.embulk:embulk-junit4:0.10.50" + testImplementation "org.embulk:embulk-spi:0.11" + testImplementation "org.embulk:embulk-core:0.11.0" + testImplementation "org.embulk:embulk-deps:0.11.0" + testImplementation "org.embulk:embulk-junit4:0.11.0" testImplementation "com.google.guava:guava:18.0" testImplementation "org.embulk:embulk-formatter-csv:0.10.42" diff --git a/gradle.lockfile b/gradle.lockfile index 5dd95775d..0e918882f 100644 --- a/gradle.lockfile +++ b/gradle.lockfile @@ -10,7 +10,7 @@ org.embulk:embulk-spi:0.11=compileClasspath org.embulk:embulk-util-config:0.3.4=compileClasspath,runtimeClasspath org.embulk:embulk-util-csv:0.2.3=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.embulk:embulk-util-rubytime:0.3.3=compileClasspath,runtimeClasspath org.embulk:embulk-util-text:0.1.3=compileClasspath,runtimeClasspath org.embulk:embulk-util-timestamp:0.2.2=compileClasspath,runtimeClasspath diff --git a/src/main/java/org/embulk/parser/csv/CsvParserPlugin.java b/src/main/java/org/embulk/parser/csv/CsvParserPlugin.java index 112932174..2ee7aaf5d 100644 --- a/src/main/java/org/embulk/parser/csv/CsvParserPlugin.java +++ b/src/main/java/org/embulk/parser/csv/CsvParserPlugin.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonValue; +import java.io.IOException; import java.nio.charset.Charset; import java.time.Instant; import java.time.format.DateTimeParseException; @@ -52,7 +53,7 @@ import org.embulk.util.csv.InvalidCsvFormatException; import org.embulk.util.csv.RecordHasUnexpectedTrailingColumnException; import org.embulk.util.json.JsonParseException; -import org.embulk.util.json.JsonParser; +import org.embulk.util.json.JsonValueParser; import org.embulk.util.text.LineDecoder; import org.embulk.util.text.LineDelimiter; import org.embulk.util.text.Newline; @@ -316,7 +317,7 @@ public void run(TaskSource taskSource, final Schema schema, FileInput input, PageOutput output) { final PluginTask task = CONFIG_MAPPER_FACTORY.createTaskMapper().map(taskSource, PluginTask.class); final TimestampFormatter[] timestampFormatters = newTimestampColumnFormatters(task, task.getSchemaConfig()); - final JsonParser jsonParser = new JsonParser(); + final JsonValueParser.Builder jsonParserBuilder = JsonValueParser.builder(); final CsvTokenizer.Builder tokenizerBuilder = buildCsvTokenizerBuilder(task); final boolean allowOptionalColumns = task.getAllowOptionalColumns(); final boolean allowExtraColumns = task.getAllowExtraColumns(); @@ -419,8 +420,11 @@ public void jsonColumn(Column column) { pageBuilder.setNull(column); } else { try { - pageBuilder.setJson(column, jsonParser.parse(v)); - } catch (JsonParseException e) { + pageBuilder.setJson(column, jsonParserBuilder.build(v).readJsonValue()); + } catch (final JsonParseException e) { + // TODO support default value + throw new CsvRecordValidateException(e); + } catch (final IOException e) { // TODO support default value throw new CsvRecordValidateException(e); }