Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable character escaping by jackson

I want to include html in my JSON response.

MyClass obj= new MyCLass();
obj.setHTML("<div style='display:none'>4</div>");

ObjectMapper mapper=new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

String jsonResponse=mapper.writeValueAsString(obj);
System.out.println(jsonResponse);

O/P i get

{"html":"<div style=\"display:none\">4</div>"}

Required O/P

{"html":"<div style='display:none'>4</div>"}

Since I want to use the json response directly. Can i disable the escaping of qoutes by object mapper.

like image 351
Linesh Mohan Avatar asked Oct 08 '15 09:10

Linesh Mohan


Video Answer


1 Answers

You can annotate your getHtml method with

@JsonRawValue
like image 129
jalogar Avatar answered Sep 28 '22 07:09

jalogar