I have a webapi that returns an object containing some collection of objects, which also contains a collection of objects. Each of these objects has a bool that represents if the object is "published." See the classes below for a general idea.
public class A { public int ID { get; set; } public List<B> b { get; set;} } public class B { public List<C> c { get; set; } public List<D> d { get; set; } public bool published { get; set; } } public class C { public string Title { get; set; } public bool published { get; set; } } public class D { public string Title { get; set; } public bool published { get; set; } }
What is the best way to do this when I serialize any of these objects, if the unpublished child objects are not included, if the user does not meet the requirements, IE is not in a specific role. Can I add data attributes to my model in some way? I reviewed using custom IContractResolver , but I'm not sure if this is the best way to handle nested objects. Do I have to handle this at the serialization stage, or do I need to remove unpublished objects from children after I get the object from the database.
source share