Fix JSON float formatting#1635
Conversation
Preserve zero fraction while JSON serialization
|
Interesting addition, didn't even know this constant exists. I'm trying to think of any existing deployments we might break with this. In the case someone defined it as @ezimuel Any thoughts related to this? @pySilver Could you also add a CHANGELOG entry and some tests to it? |
|
@ruflin I can't see any way it can brake a valid setup here since on both sides data will be in a proper/expected type. Btw, its a default JSON serialization flag in elasticsearch-php library for a long time already: elastic/elasticsearch-php#481 I'll add changelog entry in a moment, but I'm unable to add tests (I've switched back from python not so long ago and not yet familiar with PHP tests yet) |
Adds a note about float serialization
Fix changelog link
|
@ruflin, I agree to add |
|
@ruflin I think its totally correct and should be a default behavior for all serialization tasks. |
|
@pySilver Could you modify your PR to this approach? |
|
@ruflin done! |
|
Thanks. Could you try to run |
|
@ruflin yeah, same thing on localhost. The reason is here: https://github.com/ruflin/Elastica/blob/master/lib/Elastica/Index/Settings.php#L207 introduced 4m ago at #1569 (Bool should be bool), changing it in my pr. |
| $args = \func_get_args(); | ||
|
|
||
| // set defaults | ||
| isset($args[1]) ? $args[1] |= JSON_PRESERVE_ZERO_FRACTION : $args[1] = JSON_PRESERVE_ZERO_FRACTION; |
There was a problem hiding this comment.
Had to read this line a few times but makes sense now :-)
There was a problem hiding this comment.
Yeah, kinda cryptic. I couldn't find easier way to append const if arg[1] is set/not set.
There was a problem hiding this comment.
$args[1] = ($args[1] ?? 0) | JSON_PRESERVE_ZERO_FRACTION;
There was a problem hiding this comment.
Thanks for chiming in @chx . Should we update the code?
|
@pySilver Thanks for the fix, not sure how that Bool thingy slipped through for so long. |
See #1634 for details