1

I have a struts Action, that serves JSON data.
This data is serialized from a POJO with basic elements, using GSON.

In localhost, with Tomcat 6, system works correct, but when I deploy the app to Weblogic 9, the result from servlet, is not OK, the resulting JSON is not properly ended (it misses a }).

This is the pojo (I omited getters and setters)

public class DMTestResponse
{
    private String codiError;
    private String descripcioError;
    private Dades dades = new Dades();

    public class Dades
    {
            private String dada1;
            private String dada2;
            private Integer dada3;
            private String dada4;
    }
}

And this is the part of code that serializes the object:

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException
{
    // Some things
    response.setContentType("application/json");
    ServletOutputStream os = response.getOutputStream();
    os.write(resp.toString().getBytes(), 0, resp.length());
    os.flush();
    os.close();
}

From tomcat, the respose is:

{"codiError": "0", "dades": {"dada1":"bla", "dada2":"bla","dada3":"50";"dada4":"text llarg suspensió"}}

But from weblogic, the respose is:

{"codiError": "0", "dades": {"dada1":"bla", "dada2":"bla","dada3":"50";"dada4":"text llarg suspensió"}

How you can see, in weblogic, the last '}' is missing.

What may be the cause ?

Roman C
  • 49,761
  • 33
  • 66
  • 176
EsteveBlanch
  • 125
  • 3
  • 12

1 Answers1

0

Different servers could be configured to for different encoding. Try

response.setContentType("application/json; charset=UTF-8");
ServletOutputStream os = response.getOutputStream();
String s = resp.toString();
byte[] ba = s.getBytes("UTF-8");
os.write(ba, 0, ba.length);
os.flush();
Roman C
  • 49,761
  • 33
  • 66
  • 176