I've recently added a @ManyToOne
& @OneToMany
association on two of the @Entity
s in my Spring MVC Project.
@Entity
public class Book {
@ManyToOne
@JoinColumn(name = "book_id")
private BookCategory category;
}
@Entity
public class BookCategory{
@OneToMany(mappedBy = "category")
private List<Book> books;
}
@RequestMapping(value = "getAllBooks", produces = "application/json")
public @ResponseBody List<Book> getAllBooks(){
return bookRepo.findAll(); // Native Spring JPA method
}
Before including the joins, I could easily populate a List
of Books (without their BookCategories) and send them to the client as a JSON response.
However, after including the joins my asynchronous request fails and I get the following error in Chrome
SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>)
On IE:
Unterminated string constant: {description: "...
Also in Chrome I see
Resource interpreted as Document but transferred with MIME type application/json:
The request itself runs fine, returning a 200, and the response looks like normal JSON array of objects. Any ideas why this might be occuring?
Thank you!