Reputation: 254
I have Hotel
entity and it has another object called Location
.
@Entity
public class Hotel implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
String name;
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="LOC_ID")
Location location;
//GETTER SETTER
}
Location
object like that:
@Entity
public class Location implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="LOC_ID")
private Long id;
String name;
public Location() {
}
public Location(String name) {
this.name = name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
I can send Location object to server ({"name":"MyNewLoc"}
).
I can send Hotel object to server with only name it's also ok ({"name":"NewHotel"}
).
But when I try to send hotel object with name and Location attribute ({"name":"New Hotel","location":{"name":"MyNewLoc"}}
), I get 400 POST error and this response;
exception:"org.springframework.http.converter.HttpMessageNotReadableException"
message:"Could not read JSON: Template must not be null or empty! (through reference chain: org.maskapsiz.sosyalkovan.domain.Hotel["location"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Template must not be null or empty! (through reference chain: org.maskapsiz.sosyalkovan.domain.Hotel["location"])"
I am using jackson-mapper-asl 1.9.13 and Spring boot.
Upvotes: 1
Views: 1810
Reputation: 254
I added @RestResource(exported = false) and it works for me.
@Entity
@RestResource(exported = false)
public class Location implements Serializable {
}
Upvotes: 3