0

I'm currently using JHipster v2.23. I had to customize the User class to add a few attributes. Everything was fine till I had to add a 1-to-n relationship to it.

public class User extends AbstractAuditingEntity implements Serializable {
    // attributes...
    private Set<MyClass> myClass = new HashSet<>();
    // gets/sets
}

From the view side, I made the needed updates to the register form, including the code needed to handle the 1-to-n relationship. However, when I try to post it to /api/register, I get the following error (it's possible to reproduce it by just setting $scope.registerAccount.myClass=[] in register.controller.js, because this array will be sent in the json when the register form is posted):

"The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers."

I've read a few posts about this problem:

  1. Spring MVC + JSON = 406 Not Acceptable
  2. spring mvc not returning json content - error 406
  3. Spring 3.x JSON status 406 "characteristics not acceptable according to the request "accept" headers ()"

And I tried a couple approaches:

  1. Adding @EnableWebMvc, but I start seeing some mapping errors;
  2. Adding some jackson dependencies, which didn't help;

I'm wondering if JHipster code is not really prepared to handle this scenario, since it doesn't seem so rare.

Has anyone faced this issue before? Any hint on how to fix this using JHipster?

Thanks in advance.

Community
  • 1
  • 1
Jodevan
  • 732
  • 1
  • 6
  • 20

1 Answers1

0

Alright. I managed to fix it. I added the "header parameter to accept all content-types":

@RequestMapping(value = "/register",
        method = RequestMethod.POST,
        headers="Accept=*/*",
        produces = MediaType.TEXT_PLAIN_VALUE)
@Timed
public ResponseEntity<?> registerAccount(@Valid @RequestBody UserDTO userDTO, HttpServletRequest request) {
    // ...
}

I'm pretty sure setting the headers just to "application/json" should work, but I haven't had the chance to test it yet.

Jodevan
  • 732
  • 1
  • 6
  • 20