fsprojects / FSharp.Json

F# JSON Reflection based serialization library
Apache License 2.0
222 stars 26 forks source link

Handle null in untyped objects #37

Closed NicoVIII closed 2 years ago

NicoVIII commented 4 years ago

Null is a very annoying thing but I encountered a problem with it with the following json:

[
  [
    "English",
    {
      "windows":[
        {
          "manualUrl":"\/downloads\/mdk\/en1installer0",
          "name":"MDK",
          "version":"1.0",
          "date":"",
          "size":"173 MB"
        }
      ],
      "mac":[
        {
          "manualUrl":"\/downloads\/mdk\/en2installer0",
          "name":"MDK",
          "version":null,
          "date":"",
          "size":"132 MB"
        }
      ]
    }
  ]
]

Because of the list formatting (first entry string, second one an object) I am using obj list list with untyped setting to deserialize it and transform it to a usable structure. But the deserialization is failing because of the (potential) null in the version field.

I therefore added a test, which checks, if FSharp.Json can serialize and deserialize such an object and tried to implement support for it.

All tests run successfully on my machine after these changes.

I hope everything is okay with this PR, please tell me if I should change something :)

vsapronov commented 4 years ago

Hi, thank you very much for this fix! Changes look good. I'm alive and will consider to merge and release it soon.

vsapronov commented 2 years ago

I think I have merged this PR: https://github.com/vsapronov/FSharp.Json/pull/55 which fixes the same problem. Feel free to reopen if it's not...