3

In an action class, I get a list of beans in conventional manner. Then I use Gson to convert this object list in a json string. This works well (as you can see as follow):

"{ "employees" : [{ "firstName":"John" , "lastName":"Doe" }, {"firstName":"Anna" , "lastName":"Smith" } , { "firstName":"Peter" , "lastName":"Jones" } ]}";

Finally, in my freemarker file I get this variable (String JSon) but, in it, all double quotes have been replaced with '& quote;'.

<@sjg.grid id="gridtable"
 caption="My title"
 dataType="json"
 href="${remoteurl}"
 pager="true"
 gridModel="${employeesInJsonString?js_string}"
 rowList="10,15,20"
 rowNum="15"
 rownumbers="true">

<sjg:gridColumn name="firstName" index="firstName" title="FirstName" sortable="false"/>
<sjg:gridColumn name="lastName" index="lastName" title="LastName" sortable="false"/>

The resulting String is the following:

"{ & quote;employees& quote; : [{ & quote;firstName& quote;:& quote;John& quote; , & quote;lastName& quote;:& quote;Doe& quote; }, {& quote;firstName& quote;:& quote;Anna& quote; , & quote;lastName& quote;:& quote;Smith& quote; } , { & quote;firstName& quote;:& quote;Peter" , & quote;lastName& quote;:& quote;Jones& quote; } ]}";

How to keep out this transformation?

PS: I already tried to prefix all double quotes by a backslash to escape the character but the result is the same (resultJsonString = jsonString.replaceAll("\"", "\\"")).

Thank you in advance for your help

  • How about replacing all double quotes to "& quote;" just after converting into String using Gson ? – Indra Uprade Jul 22 '16 at 20:28
  • The value is not printed in the shown template. I guess it's printed in `sjg.grid`, which we don't see here. Also, in what context do you see that output? Are you sure it's incorrect to be HTML-escaped there? BTW, the `gridModel` assignment looks strange too... `gridModel=employeesInJsonString` would be cleaner, assuming you are indeed supposed to pass in the JSON itself. (Same for `href`; can be written simply as `href=remoteurl`.) – ddekany Jul 22 '16 at 21:36
  • I see this output in the source code of the HTML page displayed (options_gridtable.jsonReader.root="theOutput"). The assignment use freemarker notation and it looks like to work well. Thanks, – user3531140 Jul 25 '16 at 07:27

1 Answers1

2

i think what you are looking for is simply ${yourvar?no_esc}

cosmo
  • 71
  • 3