Hi!

This week I managed to write deserialization functions and tests.

*Issues with deserialization*
Working on deserialization give me a lot thoughts about previous concepts. I rewrite Field class so now Field can't be nested. Field can only have subfields if subfields are attributes:
class ContentField(Field):
    title = Field(attribute=True) # valid
content = Field() # invalid -> raise exception in class declaration time

     def serialized_value(...):
     ...

Of course if ContentField is initialized as attribute and have subfields exception is raised (when ContentField is initialized)

I changed python datatype format returned from serializer.serialize method. Previously it was dict with serialized fields (label or field name as key) and special key __attributes__ with dict of attributes. Now it is tuple (native, attributes) where native is dict with serialized fields (or generator of dicts)

serializer.deserialize always return object instance

After first phase of serialization, python_serialized_object will be serialized by NativeFormat instance. Each format (json, xml, yaml, ...) have one NativeFormat that will translate python_serialized_object to serialized_string. I want to be able to do this: object -> python_serial = object_serializer.serialize(object) -> string_serial = native_format.serialize(python_serial) -> python_deserial = native_format.deserialize(string_serial) -> object2 = object_serializer.deserialize(python_deserial)
object2 has same content as object

Now I have:
object -> python_serial = object_serializer.serialize(object) -> object2 = object_serializer.deserialize(python_deserial)

*Tests*
I wrote some tests (NativeSerializersTests) for ObjectSerializer in django/tests/modeltests/serializers/tests.py but I'm not sure this is good place for them. I used model (Article) defined in models.py but I used it like normal object. Relation fields aren't serialized in proper way.

Until now I tested the most important functions of ObjectSerializer. Creating custom fields, attributes, rename fields (using labels).

Next I want to resolve issues with:

 * Instance creation when deserialize. I have create_instance method
   and Meta.class_name. I must do some public API from them.
 * Ensure that Field serialize method returns always simple native
   python datatypes
 * Write NativeFormat for (at least) json
 * Find better names for already defined classes, methods and files
 * More tests and documentation

When I do this serialization and deserialization will be more or less done for (non model) python objects.


--
Piotr Grabowski





--
You received this message because you are subscribed to the Google Groups "Django 
developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to