serde-ml / serde

Serialization framework for OCaml
MIT License
174 stars 11 forks source link

Read end of object JSON tokens correctly #3

Closed pjlast closed 1 year ago

pjlast commented 1 year ago

This fixes a bug where serde would be unable to deserialize JSON objects with nested records.

This happened because any encounter of } would not be read by the parser (it only peeked at the value), which causes it to speedrun to the end of the object.

I adjusted the final test to have a nested record instead, but basically, before this PR:

{
  "Record3": {
    "name": {
      "first": "Petri",
      "last": "Last"
    },
    "age": 28
  }
}

Would never parse "age": 28 , resulting in Missing_field errors.

Now Json.Parser.read_object_end is called to read the }, and the Yojson.End_of_object error raised when the end of an object is encountered is handled by ignoring it (as it is expected state).

leostera commented 1 year ago

Amazing! Thank you so much πŸ‘πŸΌπŸ‘πŸΌπŸ‘πŸΌ