[spyne] Serializing a model
burak.arslan at arskom.com.tr
Thu Jun 19 08:02:57 UTC 2014
On 06/18/14 00:27, Joseph L. Casale wrote:
> I am using get_object_as_dict to serialize some data sent to a queue with
> the json format.
> I have a model which has an xml requirement of:
> <some node>
> <node_a ATTR="1st of 2 values"/>
> <node_a ATTR="2nd of 2 values"/>
> </some node>
> Node_a can only occur zero to two times but must have distinct ATTR values for which
> only two exist.
> My model is not optimal in that the serialized dict includes 'node_a' values as a list and the
> ATTR values as another list so they no longer correlate. I need to know if node_a appears
> for which ATTR value it was sent with.
> Is their a better way to describe this model while maintaining the nesting structure?
`attribute_of` is deprecated as of 2.11. XmlData is fully functional but
nobody but a select number of people know of its existence :) (it's
nowhere in the docs yet)
ATTR = XmlAttribute(Unicode)
data = XmlData(Unicode(max_len=450, values=['1st', '2nd']))
node_a = Node.customize(max_occurs=2)
node_b = Unicode(max_len=450)
Node('data! wee!', ATTR='1st'),
Node('data! woo!', ATTR='2nd')
node_b='king of foo'
I hope that helps.
More information about the people