I have a many to one relationship: A *<-->1 B and I want to deserialize A from a JSON having B's primary key (B exists in db with that primary key):
{
"b": 1
}
I have tried the following:
@Entity
@Table(name = "table_a")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class A implements Serializable {
@JsonIgnore
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "b", unique = true, nullable = false)
private B b;
}
and
@Entity
@Table(name = "table_b")
public class B implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@OneToMany(mappedBy = "b")
private List<A> a = new ArrayList<>();
}
but object A is created with b = null
. How can I deserialize A with b property correctly instantiated from db?
Note: I am using Jackson version 2.6.1.