Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] JsonSchema校验,如何获取不符合schema定义的字段? #684

Closed
sniper-xx opened this issue Aug 12, 2022 · 4 comments
Closed
Labels
question Further information is requested
Milestone

Comments

@sniper-xx
Copy link

sniper-xx commented Aug 12, 2022

请描述您的问题

var schemaDef = """
                {
                    type: "object",
                    properties: {
                        longitude: {
                            type: "number",
                            minimum: -180,
                            maximum: 180
                        },
                        latitude: {
                            type: "number",
                            minimum: -90,
                            maximum: 90
                        }
                    },
                    required: ["longitude", "latitude"]
                }
                """;
        var schema = JSONSchema.parseSchema(schemaDef);
        var result = schema.validate(
                JSONObject.of("longitude", 201, "latitude1", 30.2741)
        );
        Console.log("Validate: {}", result.getMessage());

比如当前json中缺少'latitude' 属性, 但是校验结果只有 “required”。 我该如何知道具体需要那个属性呢?

@sniper-xx sniper-xx added the question Further information is requested label Aug 12, 2022
@wenshao wenshao added this to the 2.0.12 milestone Aug 13, 2022
@wenshao
Copy link
Member

wenshao commented Aug 14, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.12-SNAPSHOT/
问题已修复,请帮忙用2.0.12-SNAPSHOT版本验证,2.0.12版本预计在8月21日前发布

@sniper-xx
Copy link
Author

已验证。对于required 规则,有属性指示,但对于其它验证规则(如:max、min等)无属性提示。 建议在验证结果中单独增加一个API,用于获取不符合规则的所有字段信息。谢谢!

@wenshao
Copy link
Member

wenshao commented Aug 16, 2022

@sniper-xx 更新的快照版本,max/min都已经支持属性提示

@wenshao
Copy link
Member

wenshao commented Aug 20, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.12
问题已修复,请用新版本

@wenshao wenshao closed this as completed Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants