During get request, Jackson library conversion of Bean to JSON led to Type definition error after the bean file ‘User’ was renamed from ‘User’ to UserDetails and back to ‘User’. I have been using other beans with the name ‘Course’ and ‘Employee’ for get request and they seems to be working fine. I tried refactoring the bean file with 3 names – ‘User’, ‘UserDetails’, ‘UserDetail’. All of them are giving the same error. Only return method of User controller that is able to return the desired result is as below –
@RequestMapping(method = RequestMethod.GET, path = "userDataFiltered")
public MappingJacksonValue retrieveAllUsersFiltered(){
MappingJacksonValue mjv = new MappingJacksonValue(service.getAllUser());
SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.filterOutAllExcept("user_name");
FilterProvider filters = new SimpleFilterProvider().addFilter("All_User_Filter", filter);
mjv.setFilters(filters );
return mjv;
}
‘Employee’ class was created as a substitute of ‘User’ class with same implementation. It is working fine. The error seems specific to User.java file. Though I moved ahead with Employee class as a replacement for my project, I was not able to find the root cause. I tried changing the IDE from Eclipse to IntelliJ, restarted the computer, re-clonging the repository after deletion, deleting class files followed by re-building the project. None of them worked. I am curious to know the reason if anyone knows.
Sandesh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.