Hack to avoid the AutoMapping

T

ttessarolo

I've hacked the current versione of SOAP4R to let everyone tosimply
avoid the auto-mapping functionality. The Auto Mapping is really cool:
when you inport form SOAP a stream, soap4r try to instantiate the
object it receives. If your app have defined an object with the same
signature of the one you receive from soap you will find the imported
object auto mapped, and thus instantiated, with your defined class.

For instance: if your soap stream returns a complex type object called
"Item" and your app have defined an "Item" class, soap4r automatically
maps the objects. Really useful. But what if you don't want this
happen? If you want, for example, to manually map the two objects type
simply because they aren't really the same kind of objects? I've
inserted a modification in the soap4r code to let you do that in a very
simple way.

The hack consist in just one line of code inside the file:

..../ruby/1.8/soap/mapping/

in the the method:

unknownstruct2obj(node, info, map)

put in the end of the method this line:

# Hack to avoid the AutoMapping
return nil if (defined?(klass::SOAP4R_MAPPABLE_CLASS) and
klass::SOAP4R_MAPPABLE_CLASS == false)

Now you can define a class in your app as "Not Auto Mappable". To do
that you simply have to put the declaration SOAP4R_MAPPABLE_CLASS =
false inside every class you dont want to be Auto Mappable, for
instance:

class My_Class
SOAP4R_MAPPABLE_CLASS = false
end

Please note that SOAP4R_MAPPABLE_CLASS = true or the absence of that
declaration let soap4r work as usual (in Auto Mapping Mode).

If you want you can download the hacked class at:

http://tommaso.tessarolo.it/depot/rubytypeFactory.rb

I hope this simple hack could be included in next version of soa4r.

Enjoy,

Tommaso Tessarolo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top