I know this question has been asked here but I can't found a solution. So the answer in that question explain the problem :
The exception happens at EnumJavaTypeDescriptor.fromOrdinal. So my guess is that your role_id value in the database column is 2.
But there are only two values in the UserType enum: ADMIN and USER. ADMIN's ordinal is 0, and USER's ordinal is 1. So if your row contains 2 in the user_type column, it's an invalid ordinal for the UserType enum.
In the database I have two values 1 and 2 representing two strings "black" and "white" so I cannot change them from 1 and 2 to 0 and 1. So I should handle it in my java code so I tried this but I keep getting the same error
public enum TypeColor {
black(1),
white(2);
private int val;
private TypeColor(int val) {
this.val = val;
}
}
UPDATE
here is the entity that uses that enum
@Entity
@Table(name = "BOOKS")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Book implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
private TypeColor typeColor;
//other attributes, getters, setters
}
in Controller when I try to get all books, I got that error (in the title)
@GetMapping("/books")
public ResponseEntity<List<Book>> getAllBooks(@org.springdoc.api.annotations.ParameterObject Pageable pageable) {
log.debug("REST request to get a page of Books");
Page<Rdv> page = bookRepository.findAll(pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page);
return ResponseEntity.ok().headers(headers).body(page.getContent());
}