From a4426cf2de9f088de861eb4b57e3e93f48b1a8d2 Mon Sep 17 00:00:00 2001 From: dvz5 Date: Sat, 31 Oct 2015 09:01:40 +0100 Subject: [PATCH] Update BaseObject.mustache Fix deserialization. --- .../src/main/resources/perl/BaseObject.mustache | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache index f58c180dbf..57a3e5e5fd 100644 --- a/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache @@ -36,28 +36,30 @@ sub TO_JSON { return $_data; } -# from json string +# from Perl hashref sub from_hash { my ($self, $hash) = @_; + # loop through attributes and use swagger_types to deserialize the data while ( my ($_key, $_type) = each %{$self->get_swagger_types} ) { + my $_json_attribute = $self->get_attribute_map->{$_key}; if ($_type =~ /^array\[/i) { # array my $_subclass = substr($_type, 6, -1); my @_array = (); - foreach my $_element (@{$hash->{$self->get_attribute_map->{$_key}}}) { + foreach my $_element (@{$hash->{$_json_attribute}}) { push @_array, $self->_deserialize($_subclass, $_element); } $self->{$_key} = \@_array; - } elsif (defined $hash->{$_key}) { #hash(model), primitive, datetime - $self->{$_key} = $self->_deserialize($_type, $hash->{$self->get_attribute_map->{$_key}}); + } elsif (exists $hash->{$_json_attribute}) { #hash(model), primitive, datetime + $self->{$_key} = $self->_deserialize($_type, $hash->{$_json_attribute}); } else { - $log->debugf("warning: %s not defined\n", $_key); + $log->debugf("Warning: %s (%s) does not exist in input hash\n", $_key, $_json_attribute); } } return $self; } - + # deserialize non-array data sub _deserialize { my ($self, $type, $data) = @_;