1
私はこのコードを郵便配達で試していますが、何も問題なく動作します。kotlinデータクラスHttpMessageNotReadableException
何私が送っ:
{
"name":"front_msel",
"gitlabId": "83",
"fichierVersion":"VERSION"
}
マイ春コントローラ:
@RestController
@RequestMapping("/projects")
class ProjectController(val projectRepository: ProjectRepository) {
private val log = LoggerFactory.getLogger(ProjectController::class.java)
@PostMapping()
fun saveProject(@RequestBody payload: Project): String {
log.info("project: '{}'", payload.toString())
return projectRepository.save(payload).gitlabId?:"-1"
}
}
私は何を得る:
{
"timestamp": 1505917417221,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.http.converter.HttpMessageNotReadableException",
"message": "JSON parse error: Can not construct instance of com.......model.Project: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.......model.Project: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)\n at [Source: [email protected]; line: 2, column: 2]",
"path": "/projects"
}
マイプロジェクトデータのクラス:
私はチェックパラメータを倍増しました。文句を間違えているわけではありませんが、何がうまくいかないのですか?
EDIT:トッドに
おかげで、問題は、ゼロ引数のコンストラクタを生成するために、私のparamにnull値を追加することで解決しました。ありがとう!
data class Project(val name:String? = null, val gitlabId: String? = null, val fichierVersion: String? = null)
あなたの最初のポイントは良かったし、動作させてください!しかし、snakey_caseで自分のフィールドを変更する必要はありませんでした:)それを解決していただきありがとうございます – Z3nk