我使用Jackson Json Mapper来解析我的服务器上的查询.
例如,我正在等待适合类的查询My_class:
class My_class {
String a;
String b;
}
Run Code Online (Sandbox Code Playgroud)
我以这种方式反序列化查询:
public <T> T Deserialize(String json, Class<T> type) throws DeserializationException {
if (json == null || type == null) {
throw new IllegalArgumentException();
}
try {
return objectMapper.readValue(json, type);
} catch (JsonParseException e) {
throw new DeserializationException(e);
} catch (org.codehaus.jackson.map.JsonMappingException e) {
throw new DeserializationException(e);
} catch (IOException e) {
throw new DeserializationException(e);
}
}
Run Code Online (Sandbox Code Playgroud)
以下是两个示例查询:
{"a":"test"}
{"a":"test", "b":null}
Run Code Online (Sandbox Code Playgroud)
问题是我想知道用户何时向我发送仅包含该字段a的查询以及何时发送了b设置为字段的查询null.映射器,标志着场 …