Serialization and Materialization

I want to take a serious look at serialization and materialization in the coming days. I have some ideas on using contexts for this, similar to what has been done in validations and lazy loading.

  1.  
  2.   class Invoice
  3.     include DataMapper::Resource
  4.     include DataMapper::Serialization
  5.     property :no, String, :serialize => [:invoice_detail,:invoice_summary]
  6.     property :customer, String, :serialize => [:invoice_detail,:invoice_summary]
  7.    
  8.     has :line_items, 0..n, :serialize => [:invoice_detail]
  9.   end
  10.  
  11.   class LineItem
  12.     ..
  13.     ..
  14.     property :description, String, :serialize => [:line_item_detail, :invoice_detail]
  15.   end
  16.  
  17.    ..
  18.    ..
  19.    Invoice.all(Invoice.customer.name => "Joe’s Food").to_xml(:invoice_summary)
  20.    Invoice[23].to_json(:invoice_detail)
  21.  

Wycats had interesting ideas on how to deal with type information about the model. He had a dislike to something such as this:

  1.  
  2.   <zoo>
  3.     <name type="string">Lake Side Zoo</name>
  4.   </zoo>
  5.  

After listening to his proposal, I agree. He suggests that we have the model generate a W3C XML Schema to represent its type information. We can also generate a json version of this.

Another idea is that of pluggable serializers. We could have something like:

  1.  
  2.     to_xml_serializer = DataMapper::Serializers::StandardXMLSerializer
  3.  

Wycats is working on a Lazlo Rest server. Check it out at http://wiki.openlaszlo.org/Laszlo_on_REST

Expect to hear more about this in the next few days.

– until next time –

3 Responses

  1. Dan Kubb Says:

    I think RelaxNG should be looked at in addition to XML Schema (not W3C Schema as mentioned in the article). Not having used either before I did some research and came across alot of articles saying that RelaxNG was superior to XML Schema, and that it was possible to convert Relax NG to XML Schema, but not the reverse.. leading me to believe RelaxNG could describe a richer set of constraints.

  2. guyvdb Says:

    Hi Dan,

    Opps, typo on W3C Schema. I meant W3C XML Schema (http://www.w3.org/XML/Schema).

    I looked at RelaxNG very briefly after I heard you mention it on #datamapper (irc). I am not familiarly with it, having never used it.
    It should definitely be considered. As Wycats pointed out to me, we should build the serialization as a pluggable system. Doing so would allow us to have both XML Schema and RelaxNG and allow the end user to plug either/or into the model to describe their models meta data.

  3. guyvdb Says:

    There is also a schema for YAML: http://www.kuwata-lab.com/kwalify/

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.