Linesh Mohan
Linesh Mohan

Reputation: 93

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.

Upvotes: 5

Views: 8272

Answers (1)

jalogar
jalogar

Reputation: 1684

You can annotate your getHtml method with

@JsonRawValue

Upvotes: 10

Related Questions