REST POST controller saying: Could not read JSON: No content to map due to end-of-input

前端 未结 2 1349
孤独总比滥情好
孤独总比滥情好 2020-12-09 04:24

I\'m doing an integration test against a REST controller POST handler. Well, I\'m trying to.

It gives me the HttpMessageNotReadableException exception: Could not rea

2条回答
  •  春和景丽
    2020-12-09 05:12

    I replaced the .param() methods in favor of the .content() one:

            post("/admin/crud").headers(httpHeaders)
            .contentType(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_JSON)
            .content("{ \"firstname\" : \"" + admin0.getFirstname() + "\", \"lastname\" : \"" + admin0.getLastname() + "\", \"email\" : \"" + admin0.getEmail() + "\", \"login\" : \"" + admin0.getLogin() + "\", \"password\" : \"" + admin0.getPassword() + "\", \"passwordSalt\" : \"" + admin0.getPasswordSalt() + "\" }")
        ).andDo(print())
        .andExpect(status().isCreated())
        .andExpect(jsonPath("$.firstname").value(admin0.getFirstname()))
        .andExpect(jsonPath("$.lastname").value(admin0.getLastname()))
        .andExpect(jsonPath("$.email").value(admin0.getEmail()))
        .andExpect(jsonPath("$.login").value(admin0.getLogin()))
        .andExpect(jsonPath("$.password").value(admin0.getPassword()))
        .andExpect(jsonPath("$.passwordSalt").value(admin0.getPasswordSalt()))
        .andReturn();
    

    And it now works as expected.

提交回复
热议问题