MarkupString should support Json roundtrip
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
I am trying to Serialize/Deserialize object that using JSON contains MarkupString as field and it fails.
```
public class ContentModel
{
public MarkupString HtmlContent { get; set; }
}
[Fact]
public void SimpleRoundTripTest()
{
var data = new ContentModel
{
HtmlContent = new MarkupString("
};
var serialized = JsonSerializer.Serialize(data).ShouldNotBeNull();
var deserialized = JsonSerializer.Deserialize(serialized).ShouldNotBeNull();
deserialized.HtmlContent.ShouldBe("
}
```
### Describe the solution you'd like
Add [JsonConstructor] to MarkupString
### Additional context
_No response_
Contributor guide
Research direction
Start by locating the MarkupString type and reproduce the SimpleRoundTripTest shown in the issue with JsonSerializer. Verify that ContentModel.HtmlContent can be serialized and deserialized without failure and retains the original markup value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100