Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

Changeset 1873

Show
Ignore:
Timestamp:
07/02/07 23:45:06 (11 months ago)
Author:
nahi
Message:
  • try to call klass.soap_marshallable before mapping an XML element to the klass while unmarshalling. to avoid auto-mapping from element name, define klass.soap_marshallable method let it return false. closes #223.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/soap/mapping/rubytypeFactory.rb

    r1824 r1873  
    421421    typestr = Mapping.elename2name(node.type.name) 
    422422    klass = Mapping.class_from_name(typestr) 
     423    if klass.respond_to?(:soap_marshallable) and !klass.soap_marshallable 
     424      return nil 
     425    end 
    423426    if klass.nil? and @allow_untyped_struct 
    424427      klass = Mapping.class_from_name(typestr, true)    # lenient 
  • trunk/test/soap/test_mapping.rb

    r1548 r1873  
    11require 'test/unit' 
    22require 'soap/mapping' 
     3require 'soap/marshal' 
    34 
    45 
     
    78 
    89class TestMapping < Test::Unit::TestCase 
     10 
     11  class MappablePerson 
     12    attr_reader :name 
     13    attr_reader :age 
     14 
     15    def initialize(name, age) 
     16      @name, @age = name, age 
     17    end 
     18 
     19    def self.soap_marshallable 
     20      true 
     21    end 
     22  end 
     23 
     24  class UnmappablePerson 
     25    attr_reader :name 
     26    attr_reader :age 
     27 
     28    def initialize(name, age) 
     29      @name, @age = name, age 
     30    end 
     31 
     32    def self.soap_marshallable 
     33      false 
     34    end 
     35  end 
     36 
     37  def test_mappable 
     38    xml = <<__XML__ 
     39<?xml version="1.0" encoding="utf-8" ?> 
     40<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     41    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" 
     42    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
     43  <env:Body> 
     44    <SOAP..TestMapping..MappablePerson env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
     45      <name>nahi</name> 
     46      <age>37</age> 
     47    </SOAP..TestMapping..MappablePerson> 
     48  </env:Body> 
     49</env:Envelope> 
     50__XML__ 
     51    obj = SOAP::Marshal.load(xml) 
     52    assert_equal(SOAP::TestMapping::MappablePerson, obj.class) 
     53    # 
     54    xml = <<__XML__ 
     55<?xml version="1.0" encoding="utf-8" ?> 
     56<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     57    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" 
     58    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
     59  <env:Body> 
     60    <SOAP..TestMapping..UnmappablePerson env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
     61      <name>nahi</name> 
     62      <age>37</age> 
     63    </SOAP..TestMapping..UnmappablePerson> 
     64  </env:Body> 
     65</env:Envelope> 
     66__XML__ 
     67    obj = SOAP::Marshal.load(xml) 
     68    assert_equal(SOAP::Mapping::Object, obj.class) 
     69  end 
     70 
    971  def test_date 
    1072    targets = [