? Makefile ? blib ? doclit-array.patch ? pm_to_blib Index: lib/SOAP/Lite.pm =================================================================== RCS file: /cvsroot/soaplite/soaplite-dist/lib/SOAP/Lite.pm,v retrieving revision 1.17 diff -d -u -r1.17 Lite.pm --- lib/SOAP/Lite.pm 1 Dec 2003 15:26:17 -0000 1.17 +++ lib/SOAP/Lite.pm 15 Sep 2004 18:16:03 -0000 @@ -2078,7 +2078,24 @@ } elsif ($name =~ /^\{$SOAP::Constants::NS_ENC\}Struct$/ || !$schemaclass->can($method) && (ref $children || defined $class && $value =~ /^\s*$/)) { my $res = {}; $self->hrefs->{$id} = $res if defined $id; - %$res = map {$self->decode_object($_)} @{$children || []}; + # Decode each element of the struct. + foreach my $child (@{$children || []}) { + my ($child_name, $child_value) = $self->decode_object($child); + # Store the decoded element in the struct. If the element name is + # repeated, replace the previous scalar value with a new array + # containing both values. + my $prev = $res->{$child_name}; + if (not defined $prev) { + # first time to see this value: use scalar + $res->{$child_name} = $child_value; + } elsif (ref $prev ne "ARRAY") { + # second time to see this value: convert scalar to array + $res->{$child_name} = [ $prev, $child_value ]; + } else { + # already have an array: append to it + push @{$res->{$child_name}}, $child_value; + } + } return defined $class && $class ne 'SOAPStruct' ? bless($res => $class) : $res; } else { Index: t/01-core.t =================================================================== RCS file: /cvsroot/soaplite/soaplite-dist/t/01-core.t,v retrieving revision 1.7 diff -d -u -r1.7 01-core.t --- t/01-core.t 1 Dec 2003 15:26:17 -0000 1.7 +++ t/01-core.t 15 Sep 2004 18:16:03 -0000 @@ -10,7 +10,7 @@ use strict; use Test; -BEGIN { plan tests => 25 } +BEGIN { plan tests => 30 } use SOAP::Lite; @@ -229,3 +229,23 @@ eval { A->SOAP::b }; ok($@ =~ /^SOAP:: prefix/); } + +{ + # check deserialization of an array of multiple elements + # nested within a complex type + print "Deserialization of doc/lit arrays nested in complex types...\n"; + my $input = '100onetwo'; + my $deserializer = SOAP::Deserializer->new; + my $ret = $deserializer->deserialize($input); + my @arr = @{$ret->result->{'complexFoo'}{'arrayFoo'}}; + ok($#arr == 1); + ok("one" eq $arr[0]); + ok("two" eq $arr[1]); + + ok(100 == $ret->result->{"id"}); + + # If only one araryFoo tag is found, it's deserialized as a scalar. + $input = '100one'; + $ret = $deserializer->deserialize($input); + ok("one" eq $ret->result->{'complexFoo'}{'arrayFoo'}); +}