This is my JSON
{
"type": "user_settings",
"created_at": 1610973280043,
"data": {
"user_id": 12345,
"updated_at": "2021-01-18T15:34:40+03:00"
}
}
These are my classes:
public class BaseMessage
{
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("created_at")]
public long CreatedAt { get; set; }
[JsonProperty("data")]
public DataDTO Data { get; set; }
public string DataJson {get; set;} // <-- Here I need string like this "{ "user_id": 12345, "updated_at": "2021-01-18T15:34:40+03:00" }"
}
public class DataDTO
{
[JsonProperty("user_id")]
public int UserId { get; set; }
[JsonProperty("updated_at")]
public DateTime? UpdatedAt { get; set; }
}
So I need parsed "data" (it works ok) and save nested JSON as a string (I don't know how). Is there elegant way to save nested JSON into string property?
Something like this:
public class BaseMessage
{
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("created_at")]
public long CreatedAt { get; set; }
[JsonProperty("data")]
public DataDTO Data { get; set; }
[JsonPropertyAsString("data")] // <-- This is my fantasy :)
public string DataJson {get; set; }
}