Jackson throws JsonMappingException on deserialize; demands single-String constructor?

前端 未结 4 1113
夕颜
夕颜 2020-12-03 17:56

Another question, but it relates to this one: Deserializing JSON with Jackson - Why JsonMappingException "No suitable constructor"?

This time I am getting

4条回答
  •  孤街浪徒
    2020-12-03 18:32

    I had the same problem. For me, the solution was to switch from passing a String to the convertValue method, to an InputStream to the readValue method:

    // Instead of this:
    String jsonString = "..."
    ProtocolContainer pc = mapper.convertValue(jsonString, ProtocolContainer.class);
    
    // ... do this:
    String jsonString = "..."
    InputStream is = new StringInputStream(jsonString);
    ProtocolContainer pc = mapper.readValue(is, ProtocolContainer.class);
    

提交回复
热议问题