我们将一些数据保存在Oracle 11g的CLOB列中作为序列化JSON。之后,这些数据被回读并反序列化。但是在某些情况下,反序列化失败了(使用Jackson)。
Failed to deserialize emvData JSON into HashMap. EMVData -> weblogic.jdbc.wrapper.Clob_oracle_sql_CLOB@1e52cd
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('w' (code 119)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: java.io.StringReader@56c70524; line: 1, column: 2]
事情是没有' w'它试图反序列化的JSON中的任何字符。我怀疑它可能是一个字符编码问题... Oracle 11g服务器正在使用AL32UTF8。
这是进行序列化的代码:
public String serializeEMVData(Map<String, String> emvData) {
ObjectMapper objectMapper = new ObjectMapper();
if (emvData != null) {
try {
return objectMapper.writeValueAsString(emvData);
} catch (JsonProcessingException ex) {
logger.error("Failed to serialize EMV data as JSON", ex);
}
}
return null;
}
这是进行反序列化的代码
public static Map<String, String> deserializeEMVData(String serializedEmvData) {
HashMap<String, String> emvData = null;
if (serializedEmvData != null) {
ObjectMapper objectMapper = new ObjectMapper();
try {
emvData = objectMapper.readValue(serializedEmvData, HashMap.class);
} catch (IOException e) {
logger.error("Failed to deserialize emvData JSON into HashMap. EMVData -> " + serializedEmvData.toString(), e);
}
}
if (emvData != null) {
return new TreeMap<String, String>(emvData);
} else {
return null;
}
}
如何告诉Java字符集是AL32UTF8还是我需要在查询中转换它....
答案 0 :(得分:0)
您是否正确地将CLOB转换为String? 看起来你正在尝试将CLOB.toString()(即“weblogic.jdbc.wrapper.Clob_oracle_sql_CLOB@1e52cd”)转换为java对象。