Так что я использую Spring mvc и Angularjs в своем приложении и по какой-то причине, когда я пытаюсь обновить сущность (Referencias.java), я получаю сообщение об ошибке, это сводит меня с ума, я не могу понять, что я делаю неправильно. ПОМОГИТЕ МНЕ, ПОЖАЛУЙСТА
это моя функция angularjs для отправки объекта на сервер:
$scope.saveReferencia = function () {
$http.post("../index/editReferencia", $scope.referenciaEdit).then(function (r) {
window.localStorage.setItem("referencia", JSON.stringify($scope.referenciaEdit));
$scope.referencia = JSON.parse(window.localStorage.getItem("referencia"));
$window.alert(r.data.mensaje);
});
$("#modalNuevaReferencia").modal("toggle");
};
А это мой бэкэнд API для сохранения отредактированной сущности:
@Secured(value = "Colaborador, Editor")
@ResponseBody
@RequestMapping(value = "/index/editReferencia")
public ModelAndView editReferencia(@RequestBody Referencias r, ModelMap map) {
Referencias r1 = referenciasRepo.findOne(r.getIdReferencia());
r1.setIdUsuario(r.getIdUsuario());
// setting other attibrutes of the entity, didnt put them here for simplicity
r1.setVolumen(r.getVolumen());
try {
referenciasRepo.saveAndFlush(r1);
map.put("mensaje", "Referencia editada correctamente");
map.put("data", r1);
} catch (Exception e) {
map.put("mensaje", "Error al actualizar la referencia");
map.put("error", e);
}
return new ModelAndView(new MappingJackson2JsonView(), map);
}
Я получаю сообщение об ошибке на консоли:
ADVERTENCIA [http-nio-8080-exec-26] org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.handleHttpMessageNotReadable Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of `org.springframework.security.core.GrantedAuthority` (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `org.springframework.security.core.GrantedAuthority` (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: (PushbackInputStream); line: 1, column: 681] (through reference chain: models.Referencias["idUsuario"]->models.Usuarios["authorities"]->java.util.ArrayList[1])
Я проверил, как тысячу раз, что отправляемый объект является правильным и содержит все необходимые атрибуты, но ошибка продолжает появляться, ПОЖАЛУЙСТА, ПОМОГИТЕ
models.Referencias
@Entity
@Table(name = "referencias")
@NamedQueries({
@NamedQuery(name = "Referencias.findAll", query = "SELECT r FROM Referencias r")})
public class Referencias implements Serializable {
@JoinColumn(name = "id_usuario", referencedColumnName = "id_usuario")
@ManyToOne
private Usuarios idUsuario;
@Column(name = "url")
private String url;
@ManyToMany
@JoinTable(name = "categorias_por_referencias", joinColumns = {
@JoinColumn(name = "id_referencia", referencedColumnName = "id_referencia")}, inverseJoinColumns = {
@JoinColumn(name = "id_categoria", referencedColumnName = "id_categoria")})
private List<Categoria> categoriaList;
@ManyToMany
@JoinTable(name = "autores_por_referencia", joinColumns = {
@JoinColumn(name = "id_referencia", referencedColumnName = "id_referencia")}, inverseJoinColumns = {
@JoinColumn(name = "id_autor", referencedColumnName = "id_autor")})
private List<Autores> autoresList;
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id_referencia")
private Integer idReferencia;
@Column(name = "nota")
private String nota;
@Column(name = "title")
private String title;
@Column(name = "informe_num")
private String informeNum;
@Column(name = "informe_tipo")
private String informeTipo;
@Column(name = "informe_serie")
private String informeSerie;
@Column(name = "informe_institution")
private String informeInstitution;
@Column(name = "arc_publication")
private String arcPublication;
@Column(name = "volumen")
private String volumen;
@Column(name = "num_vol")
private String numVol;
@Column(name = "edition")
private String edition;
@Column(name = "lugar")
private String lugar;
@Column(name = "editorial")
private String editorial;
@Column(name = "seccl_title")
private String secclTitle;
@Column(name = "tesis_universidad")
private String tesisUniversidad;
@Column(name = "pages")
private String pages;
@Column(name = "fecha")
private String fecha;
@Column(name = "fecha_ad")
private String fechaAd;
@Column(name = "fecha_mod")
private String fechaMod;
@JoinColumn(name = "id_fuente", referencedColumnName = "id_fuente")
@ManyToOne(optional = false)
private FuenteInf idFuente;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "idReferencia")
@JsonIgnore
private List<MetadatosAlimentosG> metadatosAlimentosGList;
// Standar constructors, getters and setters
Models.Usuarios
public class Usuarios implements Serializable, UserDetails {
//Other attributes
@JoinColumn(name = "id_roles", referencedColumnName = "id_roles")
@ManyToOne(optional = false)
private Roles idRol;
//Constructors and other attributes´s setters and getters
public Roles getIdRol() {
return idRol;
}
public void setIdRol(Roles idRol) {
this.idRol = idRol;
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
//Maybe this is not the right implementations?
//I think is worth mentioning every user has ONLY one role/authority on my model
List<Roles> authority = new ArrayList<>();
authority.add(idRol);
return authority;
}
}