我正在对Jackson进行一个非常简单的测试。我有一个类,并使用它的对象作为泽西方法的参数和返回值。 类是:将JSON反序列化为Java对象包含使用Jackson的集合
import java.util.List;
public class TestJsonArray {
private List<String> testString;
public List<String> getTestString() {
return testString;
}
public void setTestString(List<String> testString) {
this.testString = testString;
}
}
我有尝试将一个字符串添加到列表中测试串
@Path("/arrayObj")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Object createObjectArray(@QueryParam("param") String object) throws JsonGenerationException, JsonMappingException, IOException {
ObjectMapper objectMapper = new ObjectMapper();
TestJsonArray convertValue = objectMapper.convertValue(object, TestJsonArray.class);
convertValue.getTestString().add("hello");
return objectMapper.writeValueAsString(convertValue);
}
当我把这种方法与参数
{泽西方法“testString”:[“Hi”]}
我收到一个异常:
java.lang.IllegalArgumentException: Can not construct instance of test.rest.TestJsonArray, problem: no suitable creator method found to deserialize from JSON String
at [Source: N/A; line: -1, column: -1]
的异常在反序列化PROCESSS抛出:
TestJsonArray convertValue = objectMapper.convertValue(对象, TestJsonArray.class);
我想知道为什么会引发这个异常。我究竟做错了什么?
您是否创建了'TestJsonArray'只是为了容纳'ArrayList'?或者它包含其他字段? – sanbhat
这只是我真正的应用程序的测试表单。我真正的应用程序也包含其他字段 – pokeRex110