我正在使用Spring编写restful API。 API如下所示,列出了其类型的所有对象。
http://192.168.1.100:8021/some/api/v3/someobjs
DTO如下所示
public class SomeDTO {
@NotBlank
@Size(min = 1, max = 32, message = "Name size must be between 1 and 32.")
private String name;
@NotBlank
@Size(min = 1, max = 4000, message = "Info size must be between 1 and 4000.")
private String info;
// Setter & Getter
}
" info" value可以是JSON格式字符串。所以,我得到的可能是这样的:
{
"name": "wpdfw",
"info": "{\n \"indexName\": \"wpdfw\", \n \"urls\": [\n \"https://www.example.com/l2/api/v1\", \n \"https://www.example.com/l3/api/v1\"\n ], \n \"regions\": [\n \"wp.*.*\", \n \"wf.*.*\"\n ], \n \"policy\": \"equal\"\n}"
}
但是,我想要" info"要使用真正的JSON格式而不是字符串:
{
"name": "wpdfw",
"info": {
"indexName": "wpdfw",
"urls": ["https://www.example.com/l2/api/v1", "https://www.example.com/l3/api/v2"],
"regions": ["wp.*.*", "wf.*.*"],
"policy": "equal"
}
}
请注意JSON格式" info" value可以是任何未知的JSON层次结构。 我该怎么办?