Skip to content

Commit 63553e4

Browse files
pySilverruflin
authored andcommitted
Fix JSON float formatting (#1635)
Preserve zero fraction while JSON serialization
1 parent 9bda159 commit 63553e4

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file based on the
1010
### Bugfixes
1111
* Always set the Guzzle `base_uri` to support connecting to multiple ES hosts. [#1618](https://github.com/ruflin/Elastica/pull/1618)
1212
* Properly handle underscore prefixes in options and bulk request metadata ([cf upstream](https://github.com/elastic/elasticsearch/issues/26886). [#1621](https://github.com/ruflin/Elastica/pull/1621)
13+
* Preserve zeros while doing float serialization to JSON. [#1635](https://github.com/ruflin/Elastica/pull/1635)
1314

1415
### Added
1516

lib/Elastica/Index/Settings.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function setBlocksRead(bool $state = true): Response
204204
/**
205205
* @return bool
206206
*/
207-
public function getBlocksWrite(): Bool
207+
public function getBlocksWrite(): bool
208208
{
209209
return $this->getBool('blocks.write');
210210
}

lib/Elastica/JSON.php

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public static function stringify($args/* inherit from json_encode */)
6060
// extract arguments
6161
$args = \func_get_args();
6262

63+
// set defaults
64+
isset($args[1]) ? $args[1] |= JSON_PRESERVE_ZERO_FRACTION : $args[1] = JSON_PRESERVE_ZERO_FRACTION;
65+
6366
// run encode and output
6467
$string = \call_user_func_array('json_encode', $args);
6568

0 commit comments

Comments
 (0)