标签: oval

将jsonObject转换为模型对象时如何检测丢失的字段

我正在发送一个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)

java json annotations oval jackson

6
推荐指数
1
解决办法
4504
查看次数

从自定义椭圆形注释访问注释属性

当使用自定义椭圆注释和自定义类进行检查时,是否可以访问注释并检索使用的注释属性?

\n

椭圆形参考:https ://sebthom.github.io/oval/USERGUIDE.html#custom-constraint-annotations

\n
\n

最小的例子

\n

假设我们有 class Foo。\n它有两个带注释的字段。
\n每次,注释都有不同的myValue\xe2\x80\x93ab.

\n
class Foo {\n  @CustomAnnotation(myValue = "a")\n  public String first;\n\n  @CustomAnnotation(myValue = "b")\n  public String second;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

这是注释。
\n请注意,应使用 执行检查MyCheck.class,并为 设置一些默认值myValue

\n
@Retention(RetentionPolicy.RUNTIME)\n@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})\n@Constraint(checkWith = MyCheck.class)\npublic @interface CustomAnnotation {\n    String myValue() default "";\n}\n
Run Code Online (Sandbox Code Playgroud)\n

现在我们想使用 oval 来验证该字段。\n最重要的是,我们希望从注释中
提取值a或并在验证逻辑中使用它。bmyValue

\n
class Foo {\n  @CustomAnnotation(myValue = "a")\n  public String first;\n\n  @CustomAnnotation(myValue = "b")\n …
Run Code Online (Sandbox Code Playgroud)

java oval

5
推荐指数
1
解决办法
145
查看次数

如何在 Highchart 图表上绘制椭圆形(椭圆形)

我有两个系列及其交点。我想在图表上有一个椭圆形,中心位于交叉点。椭圆半径应根据轴单位设置,以显示每个轴的感兴趣区域。

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)

如何以编程方式在相交处绘制椭圆形并进行缩放?

javascript ellipse rect oval highcharts

1
推荐指数
1
解决办法
1163
查看次数

标签 统计

oval ×3

java ×2

annotations ×1

ellipse ×1

highcharts ×1

jackson ×1

javascript ×1

json ×1

rect ×1