Guest User

Untitled

a guest
Nov 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. {
  2. "nome": "BORUTO",
  3. "status": "COMPLETO",
  4. "dataLancado": "2015",
  5. "genero" : [{"id":1, "nome":"TERROR"},{"id":"2", "nome":"ACAO"}]
  6. }
  7.  
  8. <label ng-repeat="genero in generolist ">
  9. <input type="checkbox" checklist-model="selected.generos" checklist-value="genero" ng-model="manga.genero[selected.generos.id]"/> {{genero.nome}}
  10. </label>
  11. <pre>{{selected.generos|json}}</pre>
  12.  
  13. <input type="button" value="Salvar" ng-click="salvarMangas()"/>
  14.  
  15. 2017-11-20 13:18:07.146 WARN 4324 --- [nio-8080-exec-9] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
  16. at [Source: java.io.PushbackInputStream@659aad31; line: 1, column: 11] (through reference chain: com.mangastech.model.MangasEntity["genero"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
  17. at [Source: java.io.PushbackInputStream@659aad31; line: 1, column: 11] (through reference chain: com.mangastech.model.MangasEntity["genero"])
  18. 2017-11-20 13:18:07.147 WARN 4324 --- [nio-8080-exec-9] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
  19. at [Source: java.io.PushbackInputStream@659aad31; line: 1, column: 11] (through reference chain: com.mangastech.model.MangasEntity["genero"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
  20. at [Source: java.io.PushbackInputStream@659aad31; line: 1, column: 11] (through reference chain: com.mangastech.model.MangasEntity["genero"])
  21.  
  22. $scope.mangas = [];
  23. $scope.manga = {};
  24. $scope.generolist = [
  25. {id:1, nome: 'TERROR'}
  26. ];
  27.  
  28. $scope.selected = {
  29. generos : []
  30. };
  31.  
  32. $scope.salvarMangas= function() {
  33. $http({
  34. method: 'POST', url: 'http://localhost:8080/manga',data:$scope.manga})
  35. .then(function (response) {
  36. $scope.mangas.push(response.data);
  37. /*carregarClientes();
  38.  
  39. $scope.manga={};*/
  40.  
  41. }, function (response) {
  42. console.log(response.data);
  43. console.log(response.status);
  44. });
  45. };
  46.  
  47. //Cadastra novo Manga
  48. @RequestMapping(value="/manga", method=RequestMethod.POST)
  49. public MangasEntity cadastrarManga(@Valid @RequestBody MangasEntity manga){
  50. return mangaRepository.save(manga);
  51. }
  52.  
  53. public class MangasEntity implements Serializable {
  54.  
  55. private static final long serialVersionUID = 1L;
  56. private Long id;
  57. private String nome;
  58. private Status status;
  59. private int dataLancado;
  60.  
  61. @JsonIgnoreProperties("manga")
  62. private AutorEntity autor;
  63.  
  64. private List<GenerosEntity> genero = new ArrayList<>();
  65.  
  66. @Id
  67. @GeneratedValue(strategy = GenerationType.IDENTITY)
  68. @Column(name="id")
  69. public Long getId() {
  70. return id;
  71. }
  72.  
  73. public void setId(Long id) {
  74. this.id = id;
  75. }
  76.  
  77. @Column(name="nome")
  78. public String getNome() {
  79. return nome;
  80. }
  81.  
  82. public void setNome(String nome) {
  83. this.nome = nome;
  84. }
  85.  
  86. @Enumerated(EnumType.STRING)
  87. @Column(name="status")
  88. public Status getStatus() {
  89. return status;
  90. }
  91.  
  92.  
  93. public void setStatus(Status status) {
  94. this.status = status;
  95. }
  96.  
  97. @Column
  98. public int getDataLancado() {
  99. return dataLancado;
  100. }
  101.  
  102. public void setDataLancado(int dataLancado) {
  103. this.dataLancado = dataLancado;
  104. }
  105.  
  106. @ManyToOne(fetch = FetchType.EAGER)
  107. @JoinTable(name="mangas_autor",
  108. joinColumns=@JoinColumn(name="manga_id",referencedColumnName="id"),
  109. inverseJoinColumns = @JoinColumn(name="autor_id",referencedColumnName="id"))
  110.  
  111. public AutorEntity getAutor() {
  112. return autor;
  113. }
  114.  
  115. public void setAutor(AutorEntity autor) {
  116. this.autor = autor;
  117. }
  118.  
  119.  
  120. @ManyToMany(targetEntity = GenerosEntity.class)
  121. @JoinTable(name="mangas_generos",
  122. joinColumns=@JoinColumn(name="manga_id", referencedColumnName="id"),
  123. inverseJoinColumns=@JoinColumn(name="genero_id", referencedColumnName="id")
  124. )
  125.  
  126. public List<GenerosEntity> getGenero() {
  127. return this.genero;
  128. }
  129.  
  130.  
  131. public void setGenero(List<GenerosEntity> genero) {
  132. this.genero = genero;
  133. }
  134.  
  135. public MangasEntity() {
  136. super();
  137. }
  138.  
  139.  
  140. public MangasEntity(Long id, String nome, Status status, int dataLancado, AutorEntity autor,
  141. List<GenerosEntity> genero) {
  142. super();
  143. this.id = id;
  144. this.nome = nome;
  145. this.status = status;
  146. this.dataLancado = dataLancado;
  147. this.autor = autor;
  148. this.genero = genero;
  149. }
  150.  
  151. public MangasEntity(Long id){
  152. this.id = id;
  153. }
  154. }
  155.  
  156. public class GenerosEntity implements Serializable {
  157.  
  158.  
  159. private static final long serialVersionUID = 1L;
  160. private Long id;
  161. private String nome;
  162.  
  163. @JsonIgnore
  164. private List<MangasEntity> manga ;
  165.  
  166. @Id
  167. @GeneratedValue(strategy = GenerationType.IDENTITY)
  168. public Long getId() {
  169. return id;
  170. }
  171.  
  172. public void setId(Long id) {
  173. this.id = id;
  174. }
  175.  
  176. @Column(name="nome")
  177. public String getNome() {
  178. return nome;
  179. }
  180.  
  181. public void setNome(String nome) {
  182. this.nome = nome;
  183. }
  184.  
  185. @ManyToMany(mappedBy="genero", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  186. public List<MangasEntity> getManga() {
  187. return manga;
  188. }
  189.  
  190. public void setManga(List<MangasEntity> manga) {
  191. this.manga = manga;
  192. }
  193.  
  194. public GenerosEntity() {
  195.  
  196. }
  197.  
  198. public GenerosEntity(Long id) {
  199. this.id = id;
  200. }
  201.  
  202. }
Add Comment
Please, Sign In to add comment