java - How to escape HTML in JSON -


i'm wondering how can escape html code in json ? i'm using jackson json mapper.

in content have various characters: tags, single quotes, double quotes, new lines character (\n), tabs etc. tried use characterescapes class, no results.

my json response blows after using characterescapes. tried escape manually, without results.

so question is, lets have:

 <p>some text</p>\n<p>"sometext"</p> 

how can send browser value of json object?

update: input is:

{     "code": {     "num": 12 },     "obj": {         "label": "somelabel",         "order": 1     },     "det": {         "part": "1",         "cont": true     },      "html": "<p>mine text</p>" } 

output:

{     "code": {     "num": 12 }, "obj": {     "label": "somelabel",     "order": 1 }, "det": {     "part":"1",     "cont": true }, "html":{"code": {     "num": 12     },     "obj": {         "label": "somelabel",         "order": 1     },     "det": {     "part":"     } 

for have found following solution: have added characterescapes jsonfactory of objectmapper class. have changed way of writting json response. instead of

objectmapper.writevalue(response.getwriter(), myobject) 

i'm doing this:

printwriter writer = response.getwriter(); writer.print(string.valueof(objectmapper.writevalueasbytes(myobject)); writer.flush(); 

and works wanted.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -