Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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?
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.
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);
var jsonCollection = Newtonsoft.Json.JsonConvert.SerializeObject(itemsToSerialize);
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?
See this: https://github.com/zpqrtbnk/Zbu.ModelsBuilder/issues/46#issuecomment-109248277
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted