Unable to retain the backslash in the java object after deserialtion
I have below json
{\"Num\":\"44566\677\"}"
When I deserialise this to object
I am loosing the backslash
Expected :6787\32433 Actual:678732433
This is what I tried
String json = "{\"num\":\"6787\32432"}";
Objectmapper obj = new Objectmapper();
obj.enable(ALLOW_BACKSLASH_ESCAPING_ANY_CAHATCTER);
obj.readvalue(json, new Typereferenxe<Map<String,String>>(){}));
Backslash itself should be escaped so try to add another backslash into your Json - change
{\"Num\":\"44566\677\"}to{\"Num\":\"44566\\677\"}Also, if you are interested you can use a simple
JsonUtilsclass for serializing and deserializing simple JSON to/from POJO. JsonUtils is a thin wrapper overObjectMapperclass. your code would become a one liner:JsonUtilsclass comes with Open Source MjgntUtils java library written and maintained by me. Here is JsonUtils Javadoc. You can get the library as maven artifact or from Github - with source code and Javadoc