I have next ajax request
$.ajax({
contentType: 'application/json',
mimeType: 'application/json',
type: frm.attr('method'),
url: frm.attr('action'),
dataType: 'json',
data: JSON.stringify(data),
success: function (response) {
alert("success" + response);
},
error: function (jqXHR) {
var errorMessage = $(jqXHR.responseText).filter('p:eq(1)').find('u').text();
alert("error " + errorMessage);
}
});
where I transmit the letter entity
@Entity
@Table(name = "LETTERS")
public class Letter {
@Id
@Column(name = "ID")
@GeneratedValue
private long id;
@Column(name = "MESSAGE")
private String message;
@Column(name = "EMAIL")
private String email;
@Column(name = "CREATING_DATE")
private Date creatingDate;
@Column(name = "DELIVERY_DATE")
private Date deliveringDate;
public Letter() {
}
//... getters and setters
}
and in my controller I can't get this entity cause unsupported media type
@RequestMapping(value = "/main", method = RequestMethod.POST)
@ResponseBody
public void addLetterToDB(@RequestBody Letter letter) {
System.out.println(letter);
}
But if I change in method signature Letter type to String type it will works, but I wanna take the entity) Pls help.