java - 为 BigDecimal 使用正确的注释
问题描述
我有一个POJO
下面提供的 Lombok 注释,
@Setter
@Getter
public class OrderDto extends BaseDto {
@JsonProperty( "products" )
private final List<String> products;
@JsonProperty( "basket_items" )
private final List<BasketItemDto> basketItems;
@JsonProperty( "timestamp" )
@MockLocalDateTime( ignoreMillis = true )
@JsonDeserialize( using = JavaOffsetDateTimeDeserializer.class )
@JsonSerialize( using = JavaOffsetDateTimeSerializer.class )
private OffsetDateTime timestamp;
@JsonProperty( "amount" )
@Min( value = 0L)
private BigDecimal amount;
@JsonProperty( "shop_id" )
private Integer shopId;
}
我想该amount
字段接受大于零的值。但是,当我应用注释时@Min( value = 0L)
并为请求提供负值时,应用程序不会中断。
我认为原因是amount
具有类型,BigDecimal
然后我使用Long
注释。
如何使用正确的注释来过滤 a 的值BigDecimal
?
更新
我尝试使用@DecimalMin("0.00")
该应用程序仍然没有中断。但是,当我提供"amount": 05
前导零时,我会收到消息,
{
"success": false,
"message": "JSON parse error: Invalid numeric value: Leading zeroes not allowed; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Invalid numeric value: Leading zeroes not allowed\n at [Source: (PushbackInputStream); line: 4, column: 9] (through reference chain: com.xyz.bbb.dto.request.RequestDto[\"order\"])"
}
解决方案
验证API的@Positive注解
推荐阅读
- java - 导出延迟初始化的 bean(实现 SelfNaming 并使用 ManagedResource 注释进行注释)会产生 IllegalStateException
- c# - 使用 Run Query at Start 更快地运行应用程序
- c - 不通过命令行写入文本文件
- neo4j - Neo4j Cypher - 匹配条件写入
- java - Android Studio SQLite 数据库创建不起作用?
- javascript - Javascript - 更改嵌入式交易视图 script.text 上的符号
- c++ - qmltestcase 找不到 c++ 类方法
- python - selenium.common.exceptions.WebDriverException:消息:GET /session/.../window/rect 与 get_window_position() 的已知命令不匹配
- python - BeautifulSoup find() 返回标签,但标签之间没有值。为什么是这样?
- html - 如何使图像也有圆角?