-
Notifications
You must be signed in to change notification settings - Fork 736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
@@ -60,6 +60,9 @@ public static function stringify($args/* inherit from json_encode */) | |||
// extract arguments | |||
$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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to read this line a few times but makes sense now :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$args[1] = ($args[1] ?? 0) | JSON_PRESERVE_ZERO_FRACTION;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for chiming in @chx . Should we update the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pySilver Thanks for the fix, not sure how that Bool thingy slipped through for so long. |
See #1634 for details