Can “PublishedContentModel” classes emitted from the ModelBuilder be serialized and used as return types from custom WebAPI controllers derived from UmbracoApiController?
If yes, are there JsonConvert overrides needed? Which ones?
Must you hand-craft POCOS to use Ditto when mapping from the type
returned from Umbraco.TypedContent (IPublishedContent) in order to
serialize without stack overflow errors?
We're in the same boat. When attempting to serialize any PublishedContentModel a stackoverflowexception occurs at runtime. Anyone have some feedback on this? I'm wondering if its a bug or simply due to the PublishedContentModels inheritance structure?
Here is how you can serialize a collection of IPublishedContent:
var collection = Model.Content.Children();
var itemsToSerialize = new List<dynamic>();
foreach (var s in collection)
{
dynamic exObj = new System.Dynamic.ExpandoObject();
var dictionary = exObj as IDictionary<string, object>;
s.Properties.ForEach(p => dictionary[p.PropertyTypeAlias] = p.Value);
var sJson = Newtonsoft.Json.JsonConvert.SerializeObject(exObj);
items.Add(sJson);
}
var jsonCollection = Newtonsoft.Json.JsonConvert.SerializeObject(itemsToSerialize);
PublishedContentModel be Serialized?
Can “PublishedContentModel” classes emitted from the ModelBuilder be serialized and used as return types from custom WebAPI controllers derived from UmbracoApiController?
If yes, are there JsonConvert overrides needed? Which ones?
Must you hand-craft POCOS to use Ditto when mapping from the type returned from Umbraco.TypedContent (IPublishedContent) in order to serialize without stack overflow errors?
Thanks, David Dimmer
Fyin.com
Hi David,
Have the same problem, did you solve the issue?
Don't want to write AutoMapper mappings for each class, return modelBuilder classes from the API would be perfect.
Thanks
We're in the same boat. When attempting to serialize any PublishedContentModel a stackoverflowexception occurs at runtime. Anyone have some feedback on this? I'm wondering if its a bug or simply due to the PublishedContentModels inheritance structure?
Here is how you can serialize a collection of IPublishedContent:
Thanks, Michaela, we'll give this a try! Any thoughts as to why the default PublishedContentModel type in U7.4 can't be serialized directly?
Cheers,
See this: https://github.com/zpqrtbnk/Zbu.ModelsBuilder/issues/46#issuecomment-109248277
is working on a reply...