mercredi 4 mars 2015

Special characters sent by Gson in Spring with @RequestMapping

I had a problem with special characters, my problem consist in:



  1. query in oracle

  2. send by spring mvc controller

  3. angular js take the json an show in the view


when i do: System.out.println(gson.toJson(result));


show me: "MÉRITOS"


but when i do the test with postman for test my restful show me: "M�ritos"


so, i had to review my jsp tags:



<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />


i had configure the web.xml



<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>


i had review mi bean in gson and the response for spring, but the problem that i found is that my oracle charset is another not compatible whit utf-8:



SELECT value FROM NLS_DATABASE_PARAMETERS where parameter='NLS_CHARACTERSET';


show me WE8ISO8859P1.


My solution was edit my @RequestMapping:



@RequestMapping(value = "xxxx", params = {"xxxx","xxxx"}, method = RequestMethod.GET, produces={"application/json; charset=ISO-8859-1"})


put charset=ISO-8859-1, so you have put the charset that you bd was configured.


Aucun commentaire:

Enregistrer un commentaire