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

fix: handle whitespace in arrays properly #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions serde_json/serde_json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ module Deserializer = struct
Ok v

let deserialize_element self s de =
Parser.skip_space s.reader;
match Parser.peek s.reader with
| Some ']' -> Ok None
| _ ->
Expand Down
30 changes: 30 additions & 0 deletions serde_json/serde_json_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,36 @@ let _serde_json_parse_test_no_key =
(error "Failed!");
assert false

type list_of_record = { records : hello list } [@@deriving deserialize]

let _serde_json_parse_test_list_of_records =
let str = {| { "records": [ { "hello": "just one element" } ] } |} in
let parsed = Serde_json.of_string deserialize_list_of_record str in
match parsed with
| Ok parsed ->
let _ = (List.hd parsed.records).hello in
Format.printf "serde_json.ser/de test %S %s\r\n%!" "parsed with no key"
(keyword "OK")
| Error _ ->
Format.printf "serde_json.ser/de test %S %s\r\n%!" "parsed with no key"
(error "Failed!");
assert false

let _serde_json_parse_test_list_of_records_with_space =
let str =
{| { "records": [ { "hello": "two elements: one" } , { "hello": "two elements: two" }] } |}
in
let parsed = Serde_json.of_string deserialize_list_of_record str in
match parsed with
| Ok parsed ->
let _ = (List.hd parsed.records).hello in
Format.printf "serde_json.ser/de test %S %s\r\n%!" "parsed with no key"
(keyword "OK")
| Error _ ->
Format.printf "serde_json.ser/de test %S %s\r\n%!" "parsed with no key"
(error "Failed!");
assert false

type with_default = {
greeting : string;
count_with_default : int; [@serde { default = 5 }]
Expand Down
Loading