title: How to get Jackson to escape a </script> in output string?
body: <p>I have a simple Java object that I'm using Jackson to serialize to JSON, and then I'm dropping that into a <code>&lt;script&gt;</code> tag in my JSP page as part of initializing a JavaScript object.  e.g.</p>
  
  <pre><code>&lt;script&gt;SomeLib.load(${someObject});&lt;/script&gt;
  </code></pre>
  
  <p>This works great <em>unless</em> one of the fields of someObject is a String that contains <code>"&lt;/script&gt;"</code>, because of <a href="https://stackoverflow.com/questions/236073/why-split-the-script-tag-when-writing-it-with-document-write">this issue</a>.  That is, if the output looks like this:</p>
  
  <pre><code>&lt;script&gt;SomeLib.load({"someValue":"hacked!&lt;/script&gt;"});&lt;/script&gt;
  </code></pre>
  
  <p>then the browser (tested in both Chrome and FF so far) believes the <code>&lt;/script&gt;</code> tag after <code>hacked!</code> is closing the script tag.  Which breaks the JavaScript and leaves <code>"});&lt;/script&gt;</code> visible to the user.</p>
  
  <p>Is there a way to get Jackson to escape that value in some fashion that will fix this problem?</p>