反序列化JSON请求无法从START_ARRAY令牌中反序列化java.lang.String实例

时间:2018-08-14 15:16:21

标签: java spring-mvc spring-boot jwt

请帮助我

  

无法从START_ARRAY令牌中反序列化java.lang.String实例    在[来源:org.springframework.mock.web.DelegatingServletInputStream@2b92e1c6;行:1,列:14](通过参考链:br.com.foca.api.config.jwt.RESTUser [“ user_name”])

我的课:

@Data
public class RESTUser {

@JsonProperty(value = "user_name")
private String userName;
private String password;
}

我的请求:

 MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
    param.add("user_name", "X");
    param.add("password", "Y");

    String json = new ObjectMapper().writeValueAsString(param);

    HttpHeaders header = new HttpHeaders();
    header.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
    header.add("Origin", "LocalTest");

    ResultActions result = mvc.perform(
            MockMvcRequestBuilders.post("/login")
                    .headers(header)
                    .content(json)
                    .accept("application/json;charset=UTF-8"))
            .andExpect(status().isOk())
            .andExpect(content().contentType("application/json;charset=UTF-8"));

下面的代码出现问题:

    RESTUser creds = new ObjectMapper().readValue(req.getInputStream(), RESTUser.class);

我正在用杰克逊操纵物体。

0 个答案:

没有答案