在我的Rest Controller的post方法请求正文中,以下类具有参数
import com.fasterxml.jackson.annotation.JsonCreator
data class Sample @JsonCreator constructor(
val id : String,
val content: String = ""
)
我要发送的发布请求仅包含id
字段,假设如果未提供content
,则它将默认为构造函数中指定的空字符串。但是我得到以下错误
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method Sample.<init>, parameter content
at com.accelerite.notification.Notification.<init>(Notification.kt) ~[classes/:na]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_141]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_141]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_141]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_141]
at com.fasterxml.jackson.databind.introspect.AnnotatedConstructor.call(AnnotatedConstructor.java:124) ~[jackson-databind-2.9.7.jar:2.9.7]
我刚开始学习Kotlin,需要一些帮助来解决此问题。