我正在尝试在JDL Kotlin中建立网站,但是JDL生成的实体和编辑表单存在问题。我有一个名为Provider
的JDL实体,一个需要引用它所属的提供者的名为Plan
的实体,以及一个同时引用了PerDayPricing
和Provider
的名为Plan
的第三个实体,全部如下JDL配置:
entity Provider {
// [...]
}
entity Plan {
// [...]
}
entity PerDayPricing {
// [...]
}
relationship OneToMany {
Provider to Plan
}
relationship OneToMany {
Provider to PerDayPricing
Plan to PerDayPricing
}
service all with serviceImpl
但是,当我尝试在计划项上创建或设置提供者字段时,它会显示以下错误:
WARN [PID] --- [ XNIO-1 task-10] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageConversionException: JSON conversion problem: Parameter specified as non-null is null: method com.example.project.domain.Plan.setPerDayPricings, parameter <set-?>; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Parameter specified as non-null is null: method com.example.project.domain.Plan.setPerDayPricings, parameter <set-?> (through reference chain: com.example.project.domain.Plan["perDayPricings"])]
PerDayPricing
在这里被引用,即使我没有更改任何项目。当我尝试在PerDayPricing项目上设置Provider字段时,出现以下错误:
WARN [PID] --- [ XNIO-1 task-32] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageConversionException: JSON conversion problem: Parameter specified as non-null is null: method com.example.project.domain.Provider.setPlans, parameter <set-?>; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Parameter specified as non-null is null: method com.example.project.domain.Provider.setPlans, parameter <set-?> (through reference chain: com.example.project.domain.PerDayPricing["provider"]->com.example.project.domain.Provider["plans"])]
我实际上不知道这里发生了什么,因为我对JHipster经验不足。我只是导入了JDL源文件,然后让JHipster根据其配置创建文件,而不更改其中的任何文件,这已经发生了。方法名称setPlans
和setPerDayPricings
的引用甚至在代码库中都不存在,因此我假设它们是由Kotlin在后台生成的?
有人知道发生了什么,如何解决?
如果生成数据类,则编译器将为您生成setter和getter。我想,当您要将实体设置为彼此时,您没有从异常中提供这些字段。 Kotlin默认不支持空值。因此,您是否必须提供这些字段或使用?将类型标记为可为空? (问号)在和类型。例如
var perDayPricings:String?
您应该使用给定的代码更新问题,以便我们可以查看问题所在。