0

Having trouble finding the right way to describe the issue to find a solution for it. But here's a quick rundown.

I'm using Newtonsoft Json plugin for the following:

A Json is being deserialized based on a 'template' which looks like:

public class Json
{
 public class Item
 {
     public string name { get; set; }
     public int id { get; set; }
     ....
     public List<Content> content{ get; set; }

     public List<IContent> ItemContents = new List<IContent>();
 }
 public class Content
 {
    <properties of contents>
 }
}

I want the interface of ItemContents to not be loaded/used during de serialization of the Json. At the moment it throws a "Type is an interface or abstract class and cannot be instantiated" error, obviously.

Contents and ItemContents are used in different ways, so I need both at the moment, it may change in the future, but for now, I need ItemContents to be part of Items when de-serialized, but not touched or used as part of that 'template', in the process (if that makes sense).

The idea is that the interfaces should be part of a list that is created during the loading process as part of the Items, to be ready for use when it comes to that.

2
  • 1
    Can't you just annotate ItemContents with the attribute [JsonIgnore] and use the constructor to build it, or in a Serialization Callback? Commented Jun 15 at 23:48
  • I think that's what I was looking for but couldn't find. Will look into it. Commented Jun 16 at 0:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.