Skip to content

Treat xs:decimal and integer types the same way in the ValueOnly JSON serialization #694

Open

Description

@s-heppner

Currently, ValueOnlyJsonEncoder._value_to_json_type() in basyx.aas.adapter.json.formats.value_only_serialization (introduced in #660) handles numeric types inconsistently:

  • xs:decimal values are converted to float before serialization, because the stdlib json cannot serialize Decimal. This rounds them to the nearest IEEE double, so we lose precision ourselves before the client sees the value:
    • Decimal("0.10000000000000000000001") → 0.1
    • Decimal(2**53 + 1) → 9007199254740992.0 (off by one, and gets a .0)
  • Integer types are passed through unchanged, and json writes them exactly at any size (2**53 + 1 → 9007199254740993). Precision is only lost if the client parses JSON numbers as doubles.

The specification allows both: IDTA-01001 maps xs:decimal to a JSON number and says that values that cannot be represented in JSON "cannot be used" (IDTA-01001 v3.1.2, Note 1). So this is not a spec violation, but the behavior should be consistent across all numeric types.

We should choose one of these approaches:

  • Keep the exact value for all types: Write the Decimal digits as a JSON number instead of going through float, and leave any rounding to the client, as we already do for integers.
  • Round all types: Also convert the unbounded integer types to float, so that every number in our output can be represented as an IEEE double.

Whichever we choose, document it in the docstring of ValueOnlyJsonEncoder, next to the note on NaN/INF.

This was found in the review of #660 (comment).

Activity

  1. added
    bug
    server
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugserver

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions