json - Java + jackson parsing error Unrecognized character escape -
i need post json string , using httpclient. following code have. other end json mapped object.
httpclient client = httpclientbuilder.create().build(); httppost post = new httppost(url); string jsondata = "{ \"provider\" : null , \"password\" : \"a\", \"userid\" : \"mlpdemo\\mlpdemoins\" }"; post.setentity(new bytearrayentity( jsondata.tostring().getbytes("utf8"))); httpresponse response = client.execute(post);
here others correctly mapping expect userid. here problem backward slash(mlpdemo\mlpdemins). guess. if send single string user id mapped without issues. eg:-
string jsondata = "{ \"provider\" : null , \"password\" : \"a\", \"userid\" : \"mlpdemoins\" }";
this works .
but need (mlpdemo\mlpdemins)to sent through post. please me out.
string jsondata = "{ \"provider\" : null , \"password\" : \"a\", \"userid\" : \"mlpdemo\\mlpdemoins\" }";
here exception im getting.
com.fasterxml.jackson.core.jsonparseexception: unrecognized character escape 'm' (code 109) @ [source: java.io.inputstreamreader@29f0a0a2; line: 1, column: 62] badrequestexception (0ea35150-f33a-4932-a31e-8a1048af53ad): 400 bad request, com.strategicgains.restexpress.serialization.deserializationexception: com.fasterxml.jackson.core.jsonparseexception: unrecognized character escape 'm' (code 109) @ [source: java.io.inputstreamreader@29f0a0a2; line: 1, column: 62] @ com.strategicgains.restexpress.request.getbodyas(request.java:165) @ com.strategicgains.restexpress.request.getbodyas(request.java:181)
mlpdemo\mlpdemoins
invalid string can't use in json . can use mlpdemo\\mlpdemoins
easily.
below code works fine me :
string jsondata = "{ \"provider\" : null , \"password\" : \"a\", \"userid\" : \"mlpdemo\\\\mlpdemoins\" }"; objectmapper mapper=new objectmapper(); system.out.println(mapper.readtree(jsondata));
it produce output json :
{"provider":null,"password":"a","userid":"mlpdemo\\mlpdemoins"}
Comments
Post a Comment