I have a object which has a field called currencySymbol which stores Euro symbol in one of its property of String type. When I convert this Object to json using Object mapper euro symbol is converted into a junk character. Below is the code I am using. Do I need to do any character encoding configuration before converting to JSON
public String convertObjectToJson(Object obj) {
long start = System.currentTimeMillis();
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
String jsonBody = null;
try {
jsonBody = objectMapper.writeValueAsString(obj);
} catch (JsonProcessingException e) {
logger.info(e.getMessage(), e.fillInStackTrace());
}
logger.debug("Conversion time for object to json :: " + (System.currentTimeMillis() - start) / 1000d);
return jsonBody;
}
Input object :
{"currencySymbol":"₹","currencyFormat":"₹0;-₹0"}
JSON output:
{"currencySymbol":"Ç","currencyFormat":"Ç0;-Ç0"}
As you can see post conversion 'Indian Rupee' symbol ₹ is turned to junk character. Same thing happens for Euro € symbol as well