I have controller method Task<IActionResult> AddAsync([FromBody] DocumentPostDTO documentDto)
and dto:
public class DocumentPostDTO
{
public string Path { get; set; }
public dynamic? Content { get; set; }
}
Content
here is a dynamic JSON that can be anything. Here are some payload examples:
{
"path": "/Hey/abc",
"content": {
"string": ")asgadfsghaspgo"
}
}
{
"path": "/Samples/1ZCTNoQduq8TXgD-",
"content": {
"string": ")XYjU)RxfMVd&34xi8M!",
"obj": {
"int": 1
}
}
}
So, when I get this Content
property I want to assign it to plain object
and save in MongoDb.
object _content = documentDto.Content;
But what I am actually getting in object
is some kind of weird System.Text.Json.JsonValueKind
object which doesn't contain the properties passed.
Result in db:
"Content": {
"_t": "System.Text.Json.JsonValueKind, System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51",
"_v": 1
}