我正在发送一个JsonObject使用网络服务。接收调用的方法有一个模型对象的方法参数,用于JsonObject传递相应的 输入。在 JsonObject成功得到转换成模型对象,但我没能测试我的一些响应从模型对象。
例如:如果输入 JSON 中缺少任何必填字段,或者如果输入 JSON 中的任何字段设置为null,那么在这两种情况下,模型对象字段都将是null。
我无法检测null是因为字段丢失还是字段设置为null.
有人可以建议我一个解决方案吗?
我最后的出路是,我将接收方法参数输入String而不是我的模型对象,然后使用条件检查,检查输入字符串并相应地获取我的响应。但是我的 JSON 输入对象非常大,我希望有比这更好的方法。
这是一个 Spring Boot 项目。
代码片段:
JSON Object being sent
{"orgType":null, "orgLocation": "Geneva" , //other fields}
@RequestMapping(value="/addOrganizations", method= RequestMethod.POST)
public ResponseEntity addOrganization(@RequestBody Organization organization){
// code goes here
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试
{"orgType":null, "orgLocation": "Geneva" , //other fields}
Run Code Online (Sandbox Code Playgroud)
或者:
{"orgLocation": "Geneva" , //other fields}
Run Code Online (Sandbox Code Playgroud)
并在addOrganization()方法内部使用调试器进行检查,则值null在两种情况下都是如此。
模型类:
public class Organization{
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private …Run Code Online (Sandbox Code Playgroud) 当使用自定义椭圆注释和自定义类进行检查时,是否可以访问注释并检索使用的注释属性?
\n椭圆形参考:https ://sebthom.github.io/oval/USERGUIDE.html#custom-constraint-annotations
\n最小的例子
\n假设我们有 class Foo。\n它有两个带注释的字段。
\n每次,注释都有不同的myValue\xe2\x80\x93a和b.
class Foo {\n @CustomAnnotation(myValue = "a")\n public String first;\n\n @CustomAnnotation(myValue = "b")\n public String second;\n}\nRun Code Online (Sandbox Code Playgroud)\n这是注释。
\n请注意,应使用 执行检查MyCheck.class,并为 设置一些默认值myValue。
@Retention(RetentionPolicy.RUNTIME)\n@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})\n@Constraint(checkWith = MyCheck.class)\npublic @interface CustomAnnotation {\n String myValue() default "";\n}\nRun Code Online (Sandbox Code Playgroud)\n现在我们想使用 oval 来验证该字段。\n最重要的是,我们希望从注释中
提取值a或并在验证逻辑中使用它。bmyValue
class Foo {\n @CustomAnnotation(myValue = "a")\n public String first;\n\n @CustomAnnotation(myValue = "b")\n …Run Code Online (Sandbox Code Playgroud) 我有两个系列及其交点。我想在图表上有一个椭圆形,中心位于交叉点。椭圆半径应根据轴单位设置,以显示每个轴的感兴趣区域。
Highcharts.chart('container', {
series: [
// first series
{
name: 'IPR',
data: [[0, 30.5],[18.5, 25.4],[30, 19.4],[38, 9.7],[42, 0.02]]
},
// second series
{
name: 'VLP',
data: [[2, 0.5],[7, 1],[14, 6],[21, 22],[29, 29.6],[40, 30.3],[50, 27.2]]
},
// intersection
{
name: 'Operating point',
data: [
[22.42, 23.35]
]
}
],
})
Run Code Online (Sandbox Code Playgroud)
如何以编程方式在相交处绘制椭圆形并进行缩放?
oval ×3
java ×2
annotations ×1
ellipse ×1
highcharts ×1
jackson ×1
javascript ×1
json ×1
rect ×1