marten icon indicating copy to clipboard operation
marten copied to clipboard

Demonstrate issue with JSON payload and Schema fields parsing

Open miry opened this issue 1 month ago • 0 comments

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

  1. The request.data hash generated from a JSON payload does not match the original JSON structure.

  2. While this behavior doesn’t affect string fields when using the Schema feature, it breaks for array fields, which are not parsed correctly. Example: {"foo": ["a", "b"]} would treated in Schema as foo => '["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

miry avatar Nov 09 '25 14:11 miry