Skip to content

[BUG]: quicktype output bug (C# System.Text.Json renderer) #2804

@mikecrowe-otp

Description

@mikecrowe-otp

Issue Type

quicktype output bug (C# System.Text.Json renderer)

Context (Environment, Version, Language)

Input Format: JSON
Output Language: C# (System.Text.Json)
CLI, npm, or app.quicktype.io: Any
Version: master (latest)

Description

When generating C# code for schemas with unions of integer and double (e.g., integer | double), the generated deserializer did not correctly distinguish between integer and floating-point JSON numbers. Both were handled as separate cases, but both matched the same Number token, causing only one branch to be taken and the other ignored.

Input Data

[1, 2.5, 3]

or any schema with a union of integer/double.

Expected Behaviour / Output

The generated C# code should correctly distinguish between integer and floating-point values in a union, deserializing them to the correct type.

Current Behaviour / Output

Both integer and double union branches matched the same Number token, so only one branch was ever taken, leading to incorrect deserialization (e.g., all numbers treated as one type).

Steps to Reproduce

  1. Generate C# code with quicktype for a schema with a union of integer and double.
  2. Attempt to deserialize a JSON array with both integer and floating-point numbers.
  3. Observe that only one type is handled.

Possible Solution

The fix is to check, when both integer and double transformers are present, whether the JSON number is an integer (using reader.TryGetInt64) or a double, and dispatch accordingly. This was implemented by:

  • Adding a check for both transformers.
  • Using reader.TryGetInt64 to distinguish integer from double.
  • Dispatching to the correct transformer for each case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions