Skip to content

Dancer2::Core::Request JSON serialize failed when serialize application/x-www-form-urlencoded #1770

@icyavocado

Description

@icyavocado

Dancer2 JSON serialize failed to serialize application/x-www-form-urlencoded

What happened: Throw error trying to serialize application/x-www-form-urlencoded
Expected behavior: Not serialize application/x-www-form-urlencoded
Reproduction

$ dancer2 gen-app -d test_app
# edit test_app.pm
package test_app;
use Dancer2;

our $VERSION = '0.1';

+ set serializer => 'JSON'; # set JSON as default serializer

post '/' => sub {
    return "Hello";
};

true;
$ plackup bin/app.psgi

Send a post request with application/x-www-form-urlencoded content

curl -X POST http://localhost:5000 \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'a=b'
# Result
{"title":"Error 400 - Bad Request","status":400,"message":"Failed to deserialize content: malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before \"a=b\") at /home/dai/projects/Dancer2-example/test_app/local/lib/perl5/Dancer2/Serializer/JSON.pm line 47.\n"}

Perl version: 5.42.0
Dancer2 version: 2.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions