Loading ...
Sorry, an error occurred while loading the content.

Deserialization of enumerated values

Expand Messages
  • Eric Jain
    Trying to get SOAP::Lite to read enumerated values, e.g.: species SOAP::Lite complains that the type Rank is unknown. How do I
    Message 1 of 5 , Jun 17, 2003
    • 0 Attachment
      Trying to get SOAP::Lite to read enumerated values, e.g.:

      <rank xsi:type="Rank">species</rank>

      SOAP::Lite complains that the type 'Rank' is unknown. How do I tell
      SOAP::Lite to treat this element as a string (i.e. simple type)?

      Note that 'Rank' is a restriction of xsd:string, but I don't assume
      SOAP::Lite would take that into account? (Currently I anyways access
      the service directly without loading the WSDL.) Perhaps SOAP::Lite
      should default to reading values as strings?
    • Eric Jain
      ... One solution is to replace the following code in Lite.pm (1863): $res = $class ? die Unrecognized type $type n : $value unless defined $res; with: $res
      Message 2 of 5 , Jun 18, 2003
      • 0 Attachment
        > <rank xsi:type="Rank">species</rank>

        One solution is to replace the following code in Lite.pm (1863):

        $res = $class ? die "Unrecognized type '$type'\n" : $value
        unless defined $res;

        with:

        $res = $value ? $value : die "Unrecognized type '$type'\n"
        unless defined $res;

        Now obviously I can't go around telling people they must modify their
        SOAP::Lite copy if they want to use my web services. So, is there any
        other way to achieve the same effect? Or, would there be any serious
        problems if this behavior was made default?

        Another issue: What's the development status of SOAP::Lite (it seems
        there hasn't been a release in more than an year)?
      • Duncan Cameron
        ... I think that a simple deserialiser will do what you want sub SOAP::Deserializer::as_rank { my $self = shift; my($value, $name, $attr, $chil, $type) = @_;
        Message 3 of 5 , Jun 18, 2003
        • 0 Attachment
          On 2003-06-18 18:55:00 Eric Jain <jain@...> wrote:

          >> <rank xsi:type="Rank">species</rank>
          >
          >One solution is to replace the following code in Lite.pm (1863):
          >
          > $res = $class ? die "Unrecognized type '$type'\n" : $value
          > unless defined $res;
          >
          >with:
          >
          > $res = $value ? $value : die "Unrecognized type '$type'\n"
          > unless defined $res;
          >
          >Now obviously I can't go around telling people they must modify their
          >SOAP::Lite copy if they want to use my web services. So, is there any
          >other way to achieve the same effect? Or, would there be any serious
          >problems if this behavior was made default?

          I think that a simple deserialiser will do what you want

          sub SOAP::Deserializer::as_rank {
          my $self = shift;
          my($value, $name, $attr, $chil, $type) = @_;
          return $value;
          }

          In your message you will need a default namespace defined though, or a
          specific namespace and prefix rank with it.

          xmlns:dc='http://www.dc/org'>
          ..
          <rank xsi:type="dc:rank">species</rank>


          >Another issue: What's the development status of SOAP::Lite (it seems
          >there hasn't been a release in more than an year)?

          Good question.

          Regards
          Duncan
        • Eric Jain
          ... Thanks, this does work, though it is a bit awkward with dozens of custom types, to say the least, especially since I believe there is no reason why this
          Message 4 of 5 , Jun 19, 2003
          • 0 Attachment
            > sub SOAP::Deserializer::as_rank {
            > my $self = shift;
            > my($value, $name, $attr, $chil, $type) = @_;
            > return $value;
            > }

            Thanks, this does work, though it is a bit awkward with dozens of
            custom types, to say the least, especially since I believe there is
            no reason why this case could not be handled automatically.

            Consider the following example:

            <status xsi:type="ns:Status">completed</status>

            A look into the WSDL would show that 'Status' is an enumeration of
            xsd:string (or some other simple type) values.

            <simpleType name="Status">
            <restriction base="xsd:string">
            <enumeration value="running" />
            <enumeration value="completed" />
            <enumeration value="failed" />
            </restriction>
            </simpleType>

            Looking this up may be overkill, but instead of failing because the
            type 'Status' is not known, the type could simply be treated as a
            simple type! So instead of:

            $res = $class ?
            die "Unrecognized type '$type'\n" :
            $value
            unless defined $res;

            one could do:

            $res = $value ?
            $value :
            die "Unrecognized type '$type'\n"
            unless defined $res;

            or perhaps even:

            $res = $value ?
            bless(\$value, $class) :
            die "Unrecognized type '$type'\n"
            unless defined $res;

            Note that using restrictions on simple types to express enumerations
            is not my invention, but is supported out-of-the-box automatically by
            other toolkits such as Axis, Glue, and even the JAXB specification.

            So, did I overlook anything? Could this modification (or something
            similar) be incorporated into SOAP::Lite? And, who is in charge? :-)
          • Byrne Reese
            As it turns out... I can help. I suggest you enter this into SOAP::Lite s bug database hosted by sourceforge. http:://sourceforge.net/projects/soaplite
            Message 5 of 5 , Jun 19, 2003
            • 0 Attachment
              As it turns out... I can help. I suggest you enter this into SOAP::Lite's bug database hosted by sourceforge.
               
              http:://sourceforge.net/projects/soaplite
               
              Development is beginning again and a new version of SOAP::Lite is due out soon. Support for WSDL is forthcoming, but you will have to be patient as it is the developers' belief that some unknown, but probably substantial rewrite of our XML Schema parser is in order... so log this as a bug so we won't lose track of it.
               
              Byrne
               
              -----Original Message-----
              From: Eric Jain [mailto:jain@...]
              Sent: Thursday, June 19, 2003 2:24 AM
              To: soaplite@yahoogroups.com
              Subject: [soaplite] Re: Deserialization of enumerated values

              > sub SOAP::Deserializer::as_rank {
              >     my $self = shift;
              >     my($value, $name, $attr, $chil, $type) = @_;
              >     return $value;
              > }

              Thanks, this does work, though it is a bit awkward with dozens of
              custom types, to say the least, especially since I believe there is
              no reason why this case could not be handled automatically.

              Consider the following example:

                <status xsi:type="ns:Status">completed</status>

              A look into the WSDL would show that 'Status' is an enumeration of
              xsd:string (or some other simple type) values.

                <simpleType name="Status">
                  <restriction base="xsd:string">
                    <enumeration value="running" />
                    <enumeration value="completed" />
                    <enumeration value="failed" />
                  </restriction>
                </simpleType>

              Looking this up may be overkill, but instead of failing because the
              type 'Status' is not known, the type could simply be treated as a
              simple type! So instead of:

                $res = $class ?
                    die "Unrecognized type '$type'\n" :
                    $value
                  unless defined $res;

              one could do:

                $res = $value ?
                    $value :
                    die "Unrecognized type '$type'\n"
                  unless defined $res;

              or perhaps even:

                $res = $value ?
                    bless(\$value, $class) :
                    die "Unrecognized type '$type'\n"
                  unless defined $res;

              Note that using restrictions on simple types to express enumerations
              is not my invention, but is supported out-of-the-box automatically by
              other toolkits such as Axis, Glue, and even the JAXB specification.

              So, did I overlook anything? Could this modification (or something
              similar) be incorporated into SOAP::Lite? And, who is in charge? :-)



              To unsubscribe from this group, send an email to:
              soaplite-unsubscribe@yahoogroups.com



              Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
            Your message has been successfully submitted and would be delivered to recipients shortly.