savonrb / nori

XML to Hash translator
MIT License
245 stars 74 forks source link

Make advanced type casting actually advanced #66

Open maxstudener opened 9 years ago

maxstudener commented 9 years ago

Right now it only support converting true/false and date and times, is there anyways you can support more type for example the standard ones in soap: http://www.pocketsoap.com/4s4c/docs/datatypes.html

    def advanced_typecasting(value)
      split = value.split
      return value if split.size > 1

      case split.first
        when "true"       then true
        when "false"      then false
        when XS_DATE_TIME then try_to_convert(value) {|x| DateTime.parse(x)}
        when XS_DATE      then try_to_convert(value) {|x| Date.parse(x)}
        when XS_TIME      then try_to_convert(value) {|x| Time.parse(x)}
        else                   value
      end
    end
tjarratt commented 9 years ago

Hey @maxstudener thanks for opening this issue. I wasn't aware that this conversion was actually happening!

It seems like we're missing signed and unsigned bytes, ints, longs, int64 in addition to floats, doubles and decimals. Arrays would also be nice to add, but starting with some of the basic types probably makes sense.

Is this something you're interested in issuing a pull request for? I don't have any WSDLs or services that have any datatypes like you've mentioned, so it would a little difficult to functionally verify this or write unit tests.

If you have any questions about how this might work, I'm more than happy to work with you and answer any questions you might about Nori, its style and existing structure.

maxstudener commented 9 years ago

I think all that needs to be done is in @@typecasts needs to be extended to add the soap types i.e int, ,ArrayOf. I had time to dig into code and found out you are trying to convert on the type attribute on each xml node which is on standard xml soap objects except when you use a soap generator set to use=literal, in the savon gem which i linked to this ticket that isnt in the response xml but it is in the wsdl definition of each object