Skip to content

Commit 2b3e452

Browse files
authored
Fix double encoding of json (#1482)
1 parent 330ddb8 commit 2b3e452

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/adapter/etl-adapter-json/src/Flow/ETL/Adapter/JSON/RowsNormalizer/EntryNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public function normalize(Entry $entry) : string|float|int|bool|array|null
2626
Entry\DateEntry::class => $entry->value()?->format($this->dateFormat),
2727
Entry\TimeEntry::class => $entry->value() ? date_interval_to_microseconds($entry->value()) : null,
2828
Entry\EnumEntry::class => $entry->value()?->name,
29+
Entry\JsonEntry::class => $entry->value(),
2930
Entry\ListEntry::class,
3031
Entry\MapEntry::class,
3132
Entry\StructureEntry::class,
32-
Entry\JsonEntry::class,
3333
Entry\XMLElementEntry::class => $entry->toString(),
3434
Entry\XMLEntry::class => $entry->toString(),
3535
default => $entry->value(),

src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JsonTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use function Flow\ETL\Adapter\JSON\from_json;
88
use function Flow\ETL\Adapter\Json\to_json;
9-
use function Flow\ETL\DSL\{average, df, from_array, overwrite, ref};
9+
use function Flow\ETL\DSL\{average, df, from_array, from_rows, int_entry, json_entry, overwrite, ref, row};
1010
use function Flow\ETL\DSL\{config, flow_context, rows};
1111
use function Flow\Filesystem\DSL\path;
1212

@@ -113,6 +113,28 @@ public function test_json_loader_overwrite_mode() : void
113113
}
114114
}
115115

116+
public function test_jsonentry_json_file() : void
117+
{
118+
$jsonObject = ['short' => 'short_description', 'long' => 'long_description'];
119+
df()
120+
->read(from_rows(rows(
121+
row(
122+
int_entry('id', 1),
123+
json_entry('nested', $jsonObject),
124+
)
125+
)))
126+
->saveMode(overwrite())
127+
->write(to_json($path = __DIR__ . '/var/test_jsonentry.json'))
128+
->run();
129+
130+
self::assertStringContainsString(
131+
<<<'JSON'
132+
[{"id":1,"nested":{"short":"short_description","long":"long_description"}}]
133+
JSON,
134+
\file_get_contents($path)
135+
);
136+
}
137+
116138
public function test_partitioning_json_file() : void
117139
{
118140
df()

0 commit comments

Comments
 (0)