com.fasterxml.jackson.databind.exc.MismatchedInputException:由于输入结束,没有要映射的内容

时间:2018-09-07 08:47:44

标签: java spring mongodb testing

RuleDTO putRuleDTO = new RuleDTO();
    putRuleDTO.setTitle("New Rule");
    putRuleDTO.setIndex(999);
    putRuleDTO.setNodes(new HashMap<String, NodeDTO>());

    ObjectMapper putMapper = new ObjectMapper();
    putMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    String putJson = putMapper.writeValueAsString(putRuleDTO);

    HttpPut httpPut = new HttpPut(getUri.toASCIIString());
    StringEntity putEntity = new StringEntity(putJson);
    httpPut.setHeader("Accept", "application/json");
    httpPut.setHeader("Content-type", "application/json");
    httpPut.setEntity(putEntity);
    HttpResponse putResponse = httpClient.execute(httpPut);
    int putHTTPcode = putResponse.getStatusLine().getStatusCode();
    HttpEntity putHtppEntity = putResponse.getEntity();
    String updateJson = EntityUtils.toString(putHtppEntity);

    ObjectMapper obMapper = new ObjectMapper();
    obMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    Rule updateRule = obMapper.readValue(updateJson, Rule.class);
    isMyRule = false;

    if (updateRule.getTitle().equals("New Rule")) {
        isMyRule = true;
    }

    correctStatus = putHTTPcode >= 200 && putHTTPcode <= 300 ? true : false;

    assertTrue(correctStatus);
    assertTrue(isMyRule);

我正在运行项目并进行测试以测试端点。我设法提出了Get和Post请求,现在我试图提出Put请求。我的数据库中有对象,我想用相同类型的新对象进行更新,并检查它是否已成功更新到最新的对象,但出现此异常。

0 个答案:

没有答案