我试图测试以下代码但没有成功:
class TestClass
{
private class ND2Customer
{
public String name;
public String description;
public String email;
public Boolean multiuser;
public String dnszone;
public String uri;
public String type;
public ND2Customer()
{
}
}
@Test
public void TestJackson() throws JsonParseException, JsonMappingException, IOException
{
String json="{\"description\": \"test1u\", \"dnszone\": \"test1.public.sevenltest.example.com.\", \"uri\": \"http://199.127.129.69/customer/test1\", \"multiuser\": true, \"type\": \"2.0.3-3146\", \"email\": \"test1@com.com\", \"name\": \"test1\"}";
ObjectMapper mapper = new ObjectMapper();
ND2Customer casted=mapper.readValue(json, ND2Customer.class);
String castedback=mapper.defaultPrettyPrintingWriter().writeValueAsString(casted);
System.out.println(castedback);
}
}
这个问题与这个问题不同: Deserializing JSON with Jackson - Why JsonMappingException "No proper constructor"?
而这个: JsonMappingException:没有找到适合类型[简单类型,类]的构造函数:无法从 JSON 对象实例化
而这个: JsonMappingException:没有找到适合类型[简单类型,类]的构造函数:无法从 JSON 对象实例化
因为我手动覆盖了默认构造函数,它不是子类。
我该如何解决这个问题?