<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>Hi Motiejus,</div><div><br></div><div>Perhaps you should look into Joe Norton's work with UBF?</div><div><br></div><div>UBF is a type system for describing contracts between services.</div><div><br></div><div><a href="http://www.sics.se/~joe/ubf/site/home.html">http://www.sics.se/~joe/ubf/site/home.html</a> (for original documentation)</div><div><br></div><div><a href="https://github.com/norton/ubf">https://github.com/norton/ubf</a> (for the current stuff)</div><div><br></div><div>There is a UBF-to-JSON converter. There is also one for Thrift, and Joe Norton has combined UBF, UBF-JSON and QuickCheck to do validation of web services.</div><div><br></div><div>I don't think UBF to XML would be particularly difficult.</div><div><br></div><div>There may be some more work that needs to be done before it fits your problem. OTOH, you might get a lot of other benefits going this route.</div><div><br></div><div>BR,</div><div>Ulf W</div><br><div><div>On 2 Aug 2011, at 10:27, Motiejus Jakštys wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hello,<br><br>I have a data structure validator. It should check if variable has<br>a pre-defined data structure.<br><br>The validator takes Erlang data type (in this example, #'bp.message'{})<br>and checks if:<br>1) to is either {participant | bpid, binary() | undefined}<br>2) module either se_port_v2 or se_transfer_v2<br><br>Part of validator schema:<br><br>schema('bp.message') -><br>    {record, 'bp.message', [<br>        {to, schema('bp.message.destination')}<br>        {module, schema('bp.message.module')},<br>    ]};<br><br>schema('bp.message.destination') -><br>    {tuple, {choice, ['participant', 'bpid']}, {choice, ['binary', undefined]}};<br><br>schema('bp.message.module') -><br>    {choice, [<br>        se_assign_v2,<br>        se_release_v2,<br>    ]};<br><br>Two questions:<br>1) I feel I could do the same with erlang -type. How do I check the data<br>structure complies?<br>2) I need serializer and deserializer to JSON, XML or any other common<br>data format. Maybe there is such a thing in the wild?<br><br>Serialized structure must not hold Erlang data type information as I<br>have to share it with third parties. It should distinguish between atom<br>and binary from schema (as well as list from tuple..). Serialized message<br>to JSON would look like this:<br><br>{ "bp.message" : {<br>    "to" : [participant, "yadda"],<br>    "module" : "se_assign_v2"<br>     }<br>}<br><br>If I will have to write one, how do I recursively crawl type definition<br>information?<br><br>Motiejus<br>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>http://erlang.org/mailman/listinfo/erlang-questions<br></div></blockquote></div><br><div>
<div>Ulf Wiger, CTO, Erlang Solutions, Ltd.</div><div><a href="http://erlang-solutions.com">http://erlang-solutions.com</a></div><div><br></div><br class="Apple-interchange-newline">
</div>
<br></body></html>