I'm trying to output a JSON file. I am using netcoreapp3.1 along with the Newtonsoft.Json NuGet. Here is my code where I enter all the information:
private BlockWrapper GetBlock()
{
var blockWrapper = new BlockWrapper
{
blocks = new List<IntBlock>
{
new SectionBlockBlock
{
text = new TextBlock
{
type = "mrkdwn",
text = "Hello! I am Multiuse Kat. How can I help you ?"
}
},
new ActionsBlockBlock
{
elements = new ElementBlock[]
{
new ElementBlock
{
type = "button",
text = new TextBlock
{
type = "plain_text",
text = "Help"
},
style = "primary",
value = "click_me_123"
}
}
},
}
};
return blockWrapper;
}
My models look like this. Notice I am using an interface with IntBlock:
public class BlockWrapper
{
public List<IntBlock> blocks { get; set; }
}
public class SectionBlockBlock : IntBlock
{
public string type { get; } = "section";
public string blockId { get; set; }
public TextBlock text { get; set; }
}
public class ActionsBlockBlock : IntBlock
{
public string type { get; } = "actions";
public string blockId { get; set; }
public ElementBlock[] elements { get; set; }
}
public class TextBlock
{
public string type { get; set; }
public string text { get; set; }
public bool? emoji { get; set; }
}
public class ElementBlock
{
public string type { get; set; }
public string action_id { get; set; }
public TextBlock text { get; set; }
public string value { get; set; }
public string style { get; set; }
}
public interface IntBlock { }
When I return new JsonResult(GetBlock()); I output this:
I'm assuming this has something to do with the interface of IntBlock. Can someone tell me how to fix this? Thanks!