Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to deserialize content: Class::XSAccessor: invalid instance method invocant: no hash ref supplied at C:/Strawberry/perl/site/lib/Dancer2/Core/Role/Serializer.pm line 71. #16

Open
aibistin opened this issue Oct 3, 2017 · 3 comments

Comments

@aibistin
Copy link

aibistin commented Oct 3, 2017

Getting this error trying to deserialize an 'axios' call :

Failed to deserialize content: Class::XSAccessor: invalid instance method invocant: no hash ref supplied at C:/Strawberry/perl/site/lib/Dancer2/Core/Role/Serializer.pm line 71.

This is the dumped headers:

Headers: bless({
"accept" => "application/json, text/plain, /",
"accept-encoding" => "gzip, deflate, br",
"accept-language" => "en-US,en;q=0.8",
"connection" => "keep-alive",
"content-length" => 123,
"content-type" => "application/json",
"dnt" => 1,
"host" => "localhost:5000",
"origin" => "http://localhost:5000",
"referer" => "http://localhost:5000/net/add/switch_end_point",
"user-agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36",
}, "HTTP::Headers::Fast")

This is the 'request->content' (which I was able to deserialize using 'from_json()':

""name":"test","device":"one","slot":"two","port":"three","interface_type":"four","description":"five","switch_type":"six"}"

I am using the latest versions of both Dancer2 and Dancer2::Plugin::REST

@yanick
Copy link

yanick commented Oct 3, 2017

Can you provide us with a minimal example of an application that reproduce the problem you're seeing?

@aibistin
Copy link
Author

aibistin commented Oct 3, 2017

`package Updates;
use Dancer2 appname => 'NetworkApp';
use Data::Dump qw/dump/;
use FindBin qw/$Bin/;
use Dancer2::Plugin::REST;

prepare_serializer_for_format;

prefix q{/add} => sub {

post q{/switch_end_point.:format} => sub {
    debug qq{Post: Adding a new switch end_point};
	my %in_param = params('body');   # fails
    # my %in_param = %{from_json( request->content ) // {}};  #  works

    if ( keys %in_param ) {
        debug qq{Got switch end_point params: } . dump( \%in_param );
    }
    else {
        my %e;
        $e{name} = ["Missing name"] unless $in_param{name};
        $e{interface_type} = ["Missing interface type"]
          unless $in_param{interface_type};
        error qq{Returning Errors: } . ( dump \%e );
        return status_422( \%e );
    }

    status_created(
        {
            message => [
                qq{ 
                     Created a new switch end_point with name, '$in_param{name}'
                      and interface '$in_param{interface_type}'
                 }
            ]
        }
    );

};

};`

---- Calling App

axios({ method: requestMethod, url: '/net/add/switch_end_point.json', /* 'data' from DevTools console: {name: "test", device: "one", slot: "two", port: "three", interface_type: "four", …} */ data: this.data() }) .then( response => { this.onSuccess(response.data); resolve(response.data); }) .catch( error => { this.onFail(error.response.data); reject(error.response.data); });

Or: I have a test repo in my GitHub account that worked when I tested it 6 months ago. Sorry
dancer-vue-webpack

@yanick
Copy link

yanick commented Oct 4, 2017

Awesome! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants