Skip to content

Commit 8837ac7

Browse files
#375: preserve whole-number floats in Avro generic wrapper
Add JSON_PRESERVE_ZERO_FRACTION to json_encode in encodeWrapped(). 3.0 now stays 3.0 (float) instead of narrowing to 3 (int). Parity suite updated: three_point_zero assertions now verify float type preservation end-to-end.
1 parent a1bc7f5 commit 8837ac7

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Serializers/Avro.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private static function encodeWrapped(mixed $data): string
202202
// Prefix: 0x00 = generic wrapper mode
203203
$io->write("\x00");
204204
$writer->write([
205-
'json' => json_encode($data, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
205+
'json' => json_encode($data, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION),
206206
'version' => 1,
207207
], $encoder);
208208

tests/Feature/V2/V2AvroParitySuiteTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ public function testFloatIntFidelityThroughFullWorkflowLifecycle(): void
7373
$this->assertIsFloat($output['input_amount'], '3.14 must stay float');
7474
$this->assertSame(42, $output['input_items_count']);
7575
$this->assertIsInt($output['input_items_count'], '42 must stay int');
76-
$this->assertSame(3, $output['three_point_zero']);
76+
$this->assertSame(3.0, $output['three_point_zero']); $this->assertIsFloat($output['three_point_zero']);
7777

7878
$activityResult = $output['activity_result'];
7979
$this->assertSame('ORD-2', $activityResult['order_id']);
8080
$this->assertIsFloat($activityResult['amount'], 'activity result float must survive');
8181
$this->assertIsInt($activityResult['items_count'], 'activity result int must survive');
82-
$this->assertSame(3, $activityResult['three_point_zero']);
82+
$this->assertSame(3.0, $activityResult['three_point_zero']); $this->assertIsFloat($activityResult['three_point_zero']);
8383

8484
$this->assertSame(['priority' => true, 'discount' => 0.15], $output['signal_payload']);
8585
}

0 commit comments

Comments
 (0)