Skip to content
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

Incorrect Serialization of Numeric Strings in BeanJsonSerializer.php #587

Open
vladaman opened this issue Dec 31, 2024 · 0 comments
Open
Labels
Type: Bug Something isn't working

Comments

@vladaman
Copy link

vladaman commented Dec 31, 2024

Issue

The BeanJsonSerializer.php incorrectly treats numeric strings as numbers during JSON serialization. This issue arises particularly in fields containing leading zeros, such as phone and company registration numbers.

Description:
When using BeanJsonSerializer.php to convert bean objects into JSON format, any field that contains numbers is treated as a numeric value rather than a string. This behavior leads to several problems, especially with fields that should preserve their original format.

Example Issue:

  • For instance, a company registration number stored as "0001234" is serialized to 1234 in the resulting JSON output. This loss of leading zeros is technically incorrect and can cause data integrity issues.

Impact:

  • This bug affects fields such as:
    • Phone numbers (which may also require leading zeros)
    • Company registration numbers (which need to maintain their original format)

Expected Result:
The JSON output should retain the original string format, resulting in "0001234" instead of 1234.

See

or it could be using NUMERIC_CHECK

$flags = JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE;

Possible Fix

Modify the BeanJsonSerializer.php to ensure that any field containing numbers that should be treated as strings (i.e., those with leading zeros) is serialized correctly without losing the leading zeros. Check for data type of the original field and don't rely on PHP is_string()

Steps to Reproduce the Issue

1. Create a bean object with a text field containing leading zeros (e.g., `"0001234"`).
2. Serialize the object using `BeanJsonSerializer.php`.
3. Check the serialized JSON output to see if the leading zeros are preserved.

Context

No response

Version

8.7.1

What browser are you currently using?

Chrome

Browser Version

No response

Environment Information

MySql

Operating System and Version

Ubuntu

@vladaman vladaman added the Type: Bug Something isn't working label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant