Java 由于objectMapper.writeValueAsString的O/P格式不正确,无法识别字段异常

Java 由于objectMapper.writeValueAsString的O/P格式不正确,无法识别字段异常,java,json,jackson,jsonschema2pojo,Java,Json,Jackson,Jsonschema2pojo,我正在尝试使用Jackson-ObjectMapper将我的hashmap(JSON)反序列化为POJO类。下面是hashmap: List<Object> setJSONValues = new ArrayList<Object>(Arrays.asList(requestObj)); List<String> setJSONKeys = apiUtility.readJSONKeys(new File("ABC.csv")); HashMap<St

我正在尝试使用Jackson-ObjectMapper将我的hashmap(JSON)反序列化为POJO类。下面是hashmap:

List<Object> setJSONValues = new ArrayList<Object>(Arrays.asList(requestObj));
List<String> setJSONKeys = apiUtility.readJSONKeys(new  File("ABC.csv"));
HashMap<String, Object> requestMap = new HashMap<String, Object>();
 if (setJSONKeys.size() == setJSONValues.size()) {
     for (int i = 0; i < setJSONKeys.size(); i++) {
                requestMap.put(setJSONKeys.get(i), setJSONValues.get(i));
     }
 }
我得到以下错误: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段 “apptDateTime”“(class Collector.MyRequestDTO)

出现上述错误是因为my
objectMapper.writeValueAsString(requestMap)
的O/p是: {“应用日期”:“2019-03-19 10:00:00”,“米”:“8682”

添加Hashmap O/p:

for (String s:requestMap.keySet())
  System.out.println("Key is "+s+"Value is "+requestMap.get(s));
输出:键为“apptDateTime”值为“2019-03-19 10:00:00”键为
“meter”值为“8682”

您读取
键的实用方法无法按预期工作(此方法:)


请注意,如果json字符串的格式为:string content=“{\'carType\”:\“Mercedes\”};
setJSONKeys
中包含的内容,则映射器工作正常。您能否显示
apiputility.readJSONKeys
的代码?看起来它没有正确返回密钥。hashmap工作正常请参见以下内容:for(字符串s:requestMap.keySet()){System.out.println(“Key是“+s+”值是“+requestMap.get(s));}输出:Key是“apptDateTime”值是“2019-03-19 10:00:00”Key是“meter”值是“8682”,这对键值显示了什么?更新了响应!!谢谢
for (String s:requestMap.keySet())
  System.out.println("Key is "+s+"Value is "+requestMap.get(s));
List<String> setJSONKeys = apiUtility.readJSONKeys(new  File("ABC.csv"));
    String key = removeQuotes(setJSONKeys.get(i));
    String value = removeQuotes(setJSONValues.get(i))
    requestMap.put(key, setJSONValues.get(i));

...

String removeQuotes(String key) {
    key = key.trim();
    key = key.substring(1, key.length() - 1); // remove quotes
    return key.trim();
}