1
我們有一些數據作爲序列化的JSON保存在Oracle 11g的CLOB列中。之後,這些數據被讀回並反序列化。然而在某些情況下,反序列化失敗(使用傑克遜)。Java JsonParseException:意外的字符從Oracle讀取JSON 11g
Failed to deserialize emvData JSON into HashMap. EMVData -> [email protected]
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('w' (code 119)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: [email protected]; 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或者我需要的代碼在查詢中將其轉換....