背景
我想从我的JsonSchema核心3应用程序中提供一些.NET,以及序列化成JSON的其他对象。由于Manatee.Json经常被更新,并且提供了对JsonSchema的良好支持,所以它们是我的首选。同时,JSON 3为返回具有魔力的对象提供了极好的支持,这些对象可以将对象转换为.NET文档。
示例:
public ActionResult<MyFancyClass> MyFancyAction()
{
return new MyFancyClass {
Property1 = "property 1 content",
Property2 = "property 2 content",
};
}输出:
{
"Property1": "property 1 content",
"Property2": "property 2 content"
}问题
JSON 3有对.NET的内部支持,它的System.Text.Json在前面的示例中使用。如果我尝试序列化Manatee.Json.Schema.JsonSchema,它的内部结构是序列化的,而不是json模式本身。
示例:
public ActionResult<MyFancyClass2> MyFancyAction2()
{
return new MyFancyClass2 {
Property1 = "property 1 content",
Property1Schema = new JsonSchema()
.Type(JsonSchemaType.String)
};
}输出:
{
"Property1": "property 1 content",
"Property1Schema": [{
"name":"type",
"supportedVersions":15,
"validationSequence":1,
"vocabulary": {
"id":"https://json-schema.org/draft/2019-09/vocab/validation",
"metaSchemaId":"https://json-schema.org/draft/2019-09/meta/validation"
}
}]
}我希望这样做:
{
"Property1": "property 1 content",
"Property1Schema": {
"type": "string",
}
}Manatee.Json.JsonValue还有一个相互冲突的内部结构,其中System.Text.Json.JsonSerializer无法正确访问内部get方法,例如,我得到了以下异常消息:
Cannot access value of type Object as type Boolean.Discovery
Manatee.Json.Schema.JsonSchema有一个.ToJson()方法,可以用来作为JsonValue获得正确的json模式,但是接下来我遇到了序列化Manatee.Json.JsonValue时提到的问题。
问题
是否有人知道如何将.NET Core 3中的默认序列化从使用System.Text.Json更改为使用Manatee.Json
Sidemark
另一种方法是启用System.Text.Json来序列化Manatee.Json结构(看看https://stackoverflow.com/q/59855362/3032543)。
发布于 2020-08-29 14:35:23
你运气真好!我刚刚发布了模式-- Manatee.Json:JsonSchema.Net的后继!它完全支持草案6到2019-09,是基于100%的System.Text.Json,它是可笑的快速!
希望这能帮上忙。
(不知道为什么我没有收到Manatee.Json标签的电子邮件。对不起,花了这么长时间才找到这个。)
https://stackoverflow.com/questions/59856062
复制相似问题