Hi, Json.Serialize and Deserialize are generating code based on type information, converting between runtime and readable representations of objects. Because this it cannot work with an interface type. If you want to use them, the data must represented in a type for which the structure is fully known.

A current solution is to convert your data structures to contain no interfaces, for example have a union type for the subtypes you want to serialize/deserialize. This needs some boilerplate code, but makes the data format closed. (There is no way to add a union case externally, while an interface could be implemented in a later project than where you would use the Json serializer macro)

However, I do see the use case for plugins outside of the main data communication/storage implementation, we will think about how to extend it to suppport (marked) interfaces.

By on 8/4/2017 9:30 AM ()

Thank you András. I follow yours advises and ended up with solution where ListModel contains interfaces which I can create/read from/to my discriminated union type. For my taste, it looks not that bad now. Nevertheless, I have to admit that it was a difficult birth and there is some sour aftertaste because some of boilerplate code I would save in OOP world. As deeply contaminated by OOP software developer the plug-in architecture is quite common design pattern for me. Usually fist I implement micro-framework for my application with common functionality and then extend it (derive classes) where I implement specific for each object properties. Here there are actually two problems: first - how to implement in the functional world this type of design (it is very difficult to resist to make hierarchy of classes); second – describe how plug-in architecture is supported by websharper. I think this topic is worth a blog article, which may save a lot of time for further f#/websharper pioneers. If there are no any such articles probably I will write one someday If I bring my https://github.com/AndreiDegtiarev/WebSharper.Community.Dashboard test project to some acceptable stage. Thank you again


By on 8/6/2017 1:03 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us
Built with WebSharper