ArangoDB - BigDecimal
ArangoDB - BigDecimal
简单示例
@Data
@Document("product")
@Accessors(chain = true)
public class Product {
@Id
private String id;
private BigDecimal cost;
}
ArangoDB 配置:
@Override
public Builder arango() {
final Builder builder = new Builder();
arangoDbConfig.getHosts().forEach(host -> builder.host(host.getHost(), host.getPort()));
return builder
.user(arangoDbConfig.getUser())
.password(arangoDbConfig.getPassword())
.registerModule(new VPackJdk8Module());
}
读取文档生成异常:
Invocation of init method failed; nested exception is org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate java.math.BigDecimal using constructor NO_CONSTRUCTOR with arguments
依赖关系:
- SpingBoot 1.5.9
- Arangodb-spring-data 1.0.1
- Velocypack-模块-jdk8 1.0.2
好吧,忘记BigDecimal映射到HashMap就好了。创建查询 (biggerThan/lessThan) 会很奇怪。我将数据类型更改为 Double.
您需要为包含BigDecimal 的class 定义JsonSerializer 和JsonDeserializer,因为ArangoDB 不支持该类型的数据。
检查此 Arango 序列化程序文档:link
简单示例
@Data
@Document("product")
@Accessors(chain = true)
public class Product {
@Id
private String id;
private BigDecimal cost;
}
ArangoDB 配置:
@Override
public Builder arango() {
final Builder builder = new Builder();
arangoDbConfig.getHosts().forEach(host -> builder.host(host.getHost(), host.getPort()));
return builder
.user(arangoDbConfig.getUser())
.password(arangoDbConfig.getPassword())
.registerModule(new VPackJdk8Module());
}
读取文档生成异常:
Invocation of init method failed; nested exception is org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate java.math.BigDecimal using constructor NO_CONSTRUCTOR with arguments
依赖关系:
- SpingBoot 1.5.9
- Arangodb-spring-data 1.0.1
- Velocypack-模块-jdk8 1.0.2
好吧,忘记BigDecimal映射到HashMap就好了。创建查询 (biggerThan/lessThan) 会很奇怪。我将数据类型更改为 Double.
您需要为包含BigDecimal 的class 定义JsonSerializer 和JsonDeserializer,因为ArangoDB 不支持该类型的数据。 检查此 Arango 序列化程序文档:link