From b72ab84a01f977bd5906257c25c824fcc7b5b50e Mon Sep 17 00:00:00 2001 From: Hans Van Akelyen Date: Tue, 29 Oct 2024 10:56:50 +0100 Subject: [PATCH] Ignore isblank check when looking at json fragments, fixes #3577 add test --- ...006-enhanced-json-output-json-fragment.hpl | 185 ++++++++++++++++++ .../golden-enhanced-json-fragment.csv | 2 + ...006-enhanced-json-output-json-fragment.hwf | 79 ++++++++ .../golden-enhanced-json-fragment.json | 16 ++ ...hanced-json-output-json-fragment UNIT.json | 28 +++ .../jsonoutputenhanced/JsonOutput.java | 2 +- 6 files changed, 311 insertions(+), 1 deletion(-) create mode 100644 integration-tests/json/0006-enhanced-json-output-json-fragment.hpl create mode 100644 integration-tests/json/datasets/golden-enhanced-json-fragment.csv create mode 100644 integration-tests/json/main-0006-enhanced-json-output-json-fragment.hwf create mode 100644 integration-tests/json/metadata/dataset/golden-enhanced-json-fragment.json create mode 100644 integration-tests/json/metadata/unit-test/0006-enhanced-json-output-json-fragment UNIT.json diff --git a/integration-tests/json/0006-enhanced-json-output-json-fragment.hpl b/integration-tests/json/0006-enhanced-json-output-json-fragment.hpl new file mode 100644 index 00000000000..a2c79e7c38e --- /dev/null +++ b/integration-tests/json/0006-enhanced-json-output-json-fragment.hpl @@ -0,0 +1,185 @@ + + + + + 0006-enhanced-json-output-json-fragment + Y + + + + Normal + 0 + + + N + 1000 + + + 2014/03/03 20:27:52.905 + - + 2008/05/14 08:28:56.657 + + + + + + Data grid + Enhanced JSON Output + Y + + + Enhanced JSON Output + Dummy (do nothing) + Y + + + + Data grid + DataGrid + + Y + + 1 + + none + + + + + value1 + value2 + {"name":"John", "age":30, "car":null} + + + + + -1 + -1 + N + part_1 + String + + + -1 + -1 + N + part_2 + String + + + -1 + -1 + N + json_fragment + String + + + + + 144 + 80 + + + + Enhanced JSON Output + EnhancedJsonOutput + + Y + + 1 + + none + + + outputValue + result + outputvalue + N + N + N + UTF-8 + N + + ${PROJECT_HOME}/output/testfile.js + 0 + json + N + N + N + N + N + Y + N + + + + + + + + + part_1 + part_1 + N + N + N + + + part_2 + part_2 + N + N + N + + + json_fragment + json_fragment + Y + N + N + + + + + 384 + 80 + + + + Dummy (do nothing) + Dummy + + Y + + 1 + + none + + + + + 576 + 80 + + + + + + diff --git a/integration-tests/json/datasets/golden-enhanced-json-fragment.csv b/integration-tests/json/datasets/golden-enhanced-json-fragment.csv new file mode 100644 index 00000000000..1fc1467f335 --- /dev/null +++ b/integration-tests/json/datasets/golden-enhanced-json-fragment.csv @@ -0,0 +1,2 @@ +outputValue +"{""result"":{""part_1"":""value1"",""part_2"":""value2"",""json_fragment"":{""name"":""John"",""age"":30,""car"":null}}}" diff --git a/integration-tests/json/main-0006-enhanced-json-output-json-fragment.hwf b/integration-tests/json/main-0006-enhanced-json-output-json-fragment.hwf new file mode 100644 index 00000000000..2945b4f0297 --- /dev/null +++ b/integration-tests/json/main-0006-enhanced-json-output-json-fragment.hwf @@ -0,0 +1,79 @@ + + + + main-0006-enhanced-json-output-json-fragment + Y + + + + - + 2020/12/09 13:24:02.438 + - + 2020/12/09 13:24:02.438 + + + + + START + + SPECIAL + + 1 + 12 + 60 + 0 + 0 + N + 0 + 1 + N + 64 + 64 + + + + Run Pipeline Unit Tests + + RunPipelineTests + + + + 0006-enhanced-json-output-json-fragment UNIT + + + N + 320 + 64 + + + + + + START + Run Pipeline Unit Tests + Y + Y + Y + + + + + + diff --git a/integration-tests/json/metadata/dataset/golden-enhanced-json-fragment.json b/integration-tests/json/metadata/dataset/golden-enhanced-json-fragment.json new file mode 100644 index 00000000000..26e00966e81 --- /dev/null +++ b/integration-tests/json/metadata/dataset/golden-enhanced-json-fragment.json @@ -0,0 +1,16 @@ +{ + "base_filename": "golden-enhanced-json-fragment.csv", + "name": "golden-enhanced-json-fragment", + "description": "", + "dataset_fields": [ + { + "field_comment": "", + "field_length": -1, + "field_type": 2, + "field_precision": -1, + "field_name": "outputValue", + "field_format": "" + } + ], + "folder_name": "${HOP_DATASETS_FOLDER}" +} \ No newline at end of file diff --git a/integration-tests/json/metadata/unit-test/0006-enhanced-json-output-json-fragment UNIT.json b/integration-tests/json/metadata/unit-test/0006-enhanced-json-output-json-fragment UNIT.json new file mode 100644 index 00000000000..eeb8cd064d1 --- /dev/null +++ b/integration-tests/json/metadata/unit-test/0006-enhanced-json-output-json-fragment UNIT.json @@ -0,0 +1,28 @@ +{ + "variableValues": [], + "database_replacements": [], + "autoOpening": true, + "basePath": "", + "golden_data_sets": [ + { + "field_mappings": [ + { + "transform_field": "outputValue", + "data_set_field": "outputValue" + } + ], + "field_order": [ + "outputValue" + ], + "data_set_name": "golden-enhanced-json-fragment", + "transform_name": "Dummy (do nothing)" + } + ], + "input_data_sets": [], + "name": "0006-enhanced-json-output-json-fragment UNIT", + "description": "", + "persist_filename": "", + "trans_test_tweaks": [], + "pipeline_filename": "./0006-enhanced-json-output-json-fragment.hpl", + "test_type": "UNIT_TEST" +} \ No newline at end of file diff --git a/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/jsonoutputenhanced/JsonOutput.java b/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/jsonoutputenhanced/JsonOutput.java index 2e5d1646588..5f5f25ad483 100644 --- a/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/jsonoutputenhanced/JsonOutput.java +++ b/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/jsonoutputenhanced/JsonOutput.java @@ -232,7 +232,7 @@ public void manageRowItems(Object[] row) throws HopException { break; default: String value = data.inputRowMeta.getString(row, data.fieldIndexes[i]); - if (putBlank) { + if (putBlank && !outputField.isJSONFragment()) { itemNode.put(jsonAttributeName, value); } else if (value != null) { if (outputField.isJSONFragment()) {