Pass String from Servlet to jquery using Gson
<p>Requirement is very simple</p>

<p>1) Preapre Gson using String Username in servlet doPost --> PASS</p>

<pre><code>String userName = "ABC123";
String username = new Gson().toJson(userName, String.class);
httpServletResponse.getWriter().write(username);
</code></pre>

<p>2) get this username at jquery --> FAIL</p>

<pre><code>        $.post('/XYZServlet', function(username) {

        if(username != null) {
            alert('i got username' + username) //here i am getting string as 'success'
            var parsed = JSON.parse(username); //gives error
</code></pre>

<p>Not able to parse string username, can anyone help?</p>