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

Discriminated union decoding doesn't work with whitespace #48

Closed
kubukoz opened this issue Jan 14, 2022 · 1 comment · Fixed by #49
Closed

Discriminated union decoding doesn't work with whitespace #48

kubukoz opened this issue Jan 14, 2022 · 1 comment · Fixed by #49
Labels
bug Something isn't working

Comments

@kubukoz
Copy link
Member

kubukoz commented Jan 14, 2022

Given this schema:

@discriminated("type")
union TestUnion {
  one: String,
  two: Integer
}

@discriminated("tpe")
union TestBiggerUnion {
  one: One,
  two: Two
}

structure One {
  value: String
}

structure Two {
  value: Integer
}

And this JSON:

""" { "tpe" : "one" , "value" : "hello" }"""

A failure is generated:

[error] [json] - Discriminated union decoding tolerates whitespace 46ms
[error] [json]   PayloadError: Expected JSON object, offset: 0x00000003, buf:
[error] [json]   +----------+-------------------------------------------------+------------------+
[error] [json]   |          |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f | 0123456789abcdef |
[error] [json]   +----------+-------------------------------------------------+------------------+
[error] [json]   | 00000000 | 20 7b 20 22 74 70 65 22 20 3a 20 22 6f 6e 65 22 |  { "tpe" : "one" |
[error] [json]   | 00000010 | 20 2c 20 22 76 61 6c 75 65 22 20 3a 20 22 68 65 |  , "value" : "he |
[error] [json]   | 00000020 | 6c 6c 6f 22 20 7d                               | llo" }           |
[error] [json]   +----------+-------------------------------------------------+------------------+

If all whitespace is removed from the JSON string, decoding succeeds.

Reproduction in #49.

kubukoz added a commit that referenced this issue Jan 14, 2022
@kubukoz
Copy link
Member Author

kubukoz commented Jan 14, 2022

As for the good news, dump-model produces a model that (after trimming whitespace between tokens) can be read by the default codecs :)

@kubukoz kubukoz added the bug Something isn't working label Jan 15, 2022
@kubukoz kubukoz changed the title Discriminated union decoding seems to be whitespace sensitive Discriminated union decoding is whitespace sensitive Jan 16, 2022
@kubukoz kubukoz changed the title Discriminated union decoding is whitespace sensitive Discriminated union decoding doesn't work with whitespace Jan 16, 2022
Baccata pushed a commit that referenced this issue May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant