'OneToMany ManyToOne JSON parse error: Cannot construct instance of (although at least one Creator exists): no String-argument constructor/factory
I'm trying to make OneToMany and ManyToOne mapping but I'm getting this Bad Request, I'm using Swagger to generate request body, the thing that I dont understand is that in RelvLineEntity I'm injecting BankSheetEntity as One and cleary it should take the BankSheetEntity Id as a FK that means in request body inside RelvLineEntity should had a field type Long of bankSheetId but when I'm trying to make a POST, inside RelvLineEntity it shows as following: "releveBancaire": "string" See it should have a Long type not a String that's why it shows :
(although at least one
> Creator exists): no String-argument constructor/factory method to
> deserialize from String value ('string')
I tried to change to Long I get 500. Tried to pass null and nothing works. *
"message": "JSON parse error: Cannot construct instance of
releve.domain.domain.BankSheet(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('string'); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance ofreleve.domain.domain.BankSheet(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('string')\n at [Source: (PushbackInputStream); line: 64, column: 25] (through reference chain: releve.domain.domain.BankSheet["RelvLine"]->java.util.ArrayList[0]->releve.domain.domain.RelvLine["BankSheet"])",
These are my entities:
public class BankSheetEntity {
@Id
private Long bankSheetId;
....///
@OneToMany(cascade = CascadeType.ALL, mappedBy = "bankSheet", targetEntity = RelvLineEntity.class, fetch = FetchType.LAZY)
private List<RelvLineEntity> relvLine;
}
==================================================================================
public class RelvLineEntity{
@Id
private Long relvLineId;
....///
@ManyToOne()
@JoinColumn(name = "bank_sheet_FK", referencedColumnName = "bankSheetId", insertable = false, updatable = false)
private BankSheetEntity bankSheet;
I think this is the right mapping of OneToMany and ManyToOne, any suggestions please.
Solution 1:[1]
Jackson is telling you it needs some way to create entities from the String values it's getting. Try adding no-argument and full argument constructors to both entities.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jalil.Jarjanazy |
