vapor / multipart-kit

🏞 Parses and serializes multipart-encoded data with Codable support.
MIT License
139 stars 41 forks source link

Decoding optional type cause error #68

Closed emilwojtaszek closed 3 years ago

emilwojtaszek commented 3 years ago

Describe the bug

This one works:

let foo = try FormDataDecoder().decode(Foo.self, from: data, boundary: "12345")

this one doesn't

let foo = try FormDataDecoder().decode(Foo?.self, from: data, boundary: "12345")

Error:

caught error: "typeMismatch(MultipartKit.OrderedDictionary<Swift.String, MultipartKit.MultipartFormData>, Swift.DecodingError.Context(codingPath: [], debugDescription: "expected single value but encountered dictionary", underlyingError: nil))"

To Reproduce

You can adjust func testFormDataDecoderW3() to see this behaviour

Expected behavior

Content should be decoded no matter if type is Foo.self or Foo?.self

Environment

Tested od mian branch

siemensikkema commented 3 years ago

@emilwojtaszek this appears to happen only when the top-level object is an optional. I'll need to look into it further. Thanks for reporting!