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.
-
-
class Invoice
-
include DataMapper::Resource
-
include DataMapper::Serialization
-
property :no, String, :serialize => [:invoice_detail,:invoice_summary]
-
property :customer, String, :serialize => [:invoice_detail,:invoice_summary]
-
-
has :line_items, 0..n, :serialize => [:invoice_detail]
-
end
-
-
class LineItem
-
..
-
..
-
property :description, String, :serialize => [:line_item_detail, :invoice_detail]
-
end
-
-
..
-
..
-
Invoice.all(Invoice.customer.name => "Joe’s Food").to_xml(:invoice_summary)
-
Invoice[23].to_json(:invoice_detail)
-
Wycats had interesting ideas on how to deal with type information about the model. He had a dislike to something such as this:
-
-
<zoo>
-
<name type="string">Lake Side Zoo</name>
-
</zoo>
-
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:
-
-
to_xml_serializer = DataMapper::Serializers::StandardXMLSerializer
-
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 –
April 12th, 2008 at 12:05 am
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.
April 12th, 2008 at 9:43 am
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.
April 12th, 2008 at 10:29 am
There is also a schema for YAML: http://www.kuwata-lab.com/kwalify/