Im getting 400 Bad Request on Ajax request all the time. I have no idea what\'s could go wrong with this. Im using:
org
I solved my problem. Here is what I did in order to make it work: Firstly I changed dependency to jackson2
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.3</version>
</dependency>
Then I annotated my Book class with @JsonProperty and @JsonIgnore. Here is my updated Book class
@Entity
@Table(name="Book")
@Indexed
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "bookId")
@JsonIgnore
private Long id;
@Column(nullable = false)
@Field(index = Index.YES, analyze=Analyze.YES, store=Store.NO)
@JsonProperty("title")
private String title;
@Column(nullable = false, unique = true)
@JsonProperty("ISBN")
private String ISBN;
@Column(nullable = false)
@Field(index = Index.YES, analyze=Analyze.YES, store=Store.NO)
@JsonProperty("author")
private String author;
@JsonProperty("publisher")
private String publisher;
@Column(length = 1000)
@JsonProperty("description")
private String description;
@JsonProperty("publicationYear")
private int publicationYear;
@JsonProperty("pages")
private int pages;
@Enumerated(EnumType.STRING)
@Column(nullable = false)
@JsonIgnore
private BookStatus bookStatus;
@ManyToMany(mappedBy = "booksWant", cascade = CascadeType.ALL)
@JsonIgnore
private List<User> user = new ArrayList<User>(0);
@OneToMany(mappedBy = "book", cascade = CascadeType.ALL)
@JsonIgnore
private List<UserBook> bookList = new ArrayList<UserBook>(0);
public Book(String title, String ISBN, String author, String publisher, String description,
int publicationYear, int pages, BookStatus bookStatus) {
this.title = title;
this.ISBN = ISBN;
this.author = author;
this.publisher = publisher;
this.description = description;
this.publicationYear = publicationYear;
this.pages = pages;
this.bookStatus = bookStatus;
}
getters and setters
}
Remove "'contentType: 'application/json'," from the ajax call