EmailAddress serialization to list

17 views
Skip to first unread message

Burak Arslan

unread,
Jan 10, 2020, 10:51:18 AM1/10/20
to jmap-d...@googlegroups.com
Hello,

I've just started to work on 'jmapd', a jmap server written in Python.
It's currently just a learning exercise but just might get serious if
there is community help.

Here's a totally useless 0.1 version that returns an arbitrary
capabilities object: https://pypi.org/project/jmapd/

I also have a question: Does the order of specification of fields in the
standard document have any meaning?

Why it matters: When using json, I always prefer to serialize well-known
complex objects to lists instead of dicts. Of course for that to work,
we need a well-defined order of fields.

Let's look at the EmailAddress object.

    >>> from spyne import *
    >>> from spyne.util.dictdoc import get_object_as_json
    >>>
    >>> class EmailAddress(ComplexModel):
    ...     _type_info = [
    ...         ('name', Unicode),
    ...         ('email', Unicode),
    ...     ]
    ...
    >>> get_object_as_json(EmailAddress(name='John Smith',
email='jo...@example.com'))
    '["John Smith", "jo...@example.com"]'
    >>> get_object_as_json(EmailAddress(email='jo...@example.com'))
    '[null, "jo...@example.com"]'

(I hope this looks right on your side)

So, as you see, because an optional field is first, I have to have null
as first element. It's annoying but I guess I can live with that.

The question is: can I rely on the order of elements staying the same?

Keep up the good work.

Best regards,
Burak ARSLAN

Neil Jenkins

unread,
Jan 11, 2020, 8:51:39 PM1/11/20
to JMAP
On Sat, 11 Jan 2020, at 02:49, Burak Arslan wrote:
I also have a question: Does the order of specification of fields in the standard document have any meaning?

No. Named properties of a JSON object are unordered. Only arrays are ordered.

Cheers,
Neil.
Reply all
Reply to author
Forward
0 new messages