marten
marten copied to clipboard
Demonstrate issue with JSON payload and Schema fields parsing
Summary
This PR introduces the use of JSON payloads and highlights an issue with how JSON data is currently parsed in Marten::HTTP::Request for #data.
While testing JSON payload parsing, I noticed that all root-level keys in the JSON payload are being converted to arrays. src.
Problems
-
The request.data hash generated from a JSON payload does not match the original JSON structure.
-
While this behavior doesn’t affect
stringfields when using the Schema feature, it breaks forarrayfields, which are not parsed correctly. Example:{"foo": ["a", "b"]}would treated in Schema asfoo => '["a","b"]'. and schema:
class RequestSchema < Marten::Schema
field :foo, :array, of: :string, max_size: 2, required: true
end
schema = RequestShcema.new(request.data)
schema.foo # => '["a", "b"]'
PS: This PR contains changes from https://github.com/martenframework/marten/pull/328