Exemplo n.º 1
0
    def test_self_referential_array_workaround(self):
        from spyne.util.dictobj import get_object_as_dict
        from pprint import pprint
        class Category(ComplexModel):
            id = Integer(min_occurs=1, max_occurs=1, nillable=False)

        Category._type_info['children'] = Array(Category)

        parent = Category()
        parent.children = [Category(id=0), Category(id=1)]

        d = get_object_as_dict(parent, Category)
        pprint(d)
        assert d['Category']['children']['Category'][0]['id'] == 0
        assert d['Category']['children']['Category'][1]['id'] == 1

        class SoapService(ServiceBase):
            @rpc(_returns=Category)
            def view_categories(ctx):
                pass

        Application([SoapService], 'service.soap',
                            in_protocol=ProtocolBase(),
                            out_protocol=ProtocolBase())
Exemplo n.º 2
0
 def process(value):
     return json.dumps(get_object_as_dict(value, self.cls,
                                             skip_depth=self.skip_depth))
Exemplo n.º 3
0
 def process(value):
     if value is not None:
         return json.dumps(get_object_as_dict(value, self.cls,
                                             skip_depth=self.skip_depth))
Exemplo n.º 4
0
 def process(value):
     return json.dumps(get_object_as_dict(value, self.cls))