added support to encode objects that implements  mapping protocol