I'm using the geonames Java client to find a city with the given postal code and country. I am having problems with umlauts - I'm getting ?-signs instead of the correct umlaut - K?ln instead of the correct Köln.
My code looks like:
PostalCodeSearchCriteria pcsq = new PostalCodeSearchCriteria();
pcsq.setCountryCode("DE");
pcsq.setPostalCode("50667");
List<PostalCode> foundList1 = WebService.postalCodeSearch(pcsq);
for (PostalCode postalCode : foundList1) {
System.out.println(postalCode.getPlaceName());
}
The problem was the incorrect encoding of the response-object of the servlet:
.....
PostalCodeSearchCriteria pcsq = new PostalCodeSearchCriteria();
pcsq.setCountryCode("DE");
pcsq.setPostalCode("50667");
List<PostalCode> foundList = WebService.postalCodeSearch(pcsq);
.....
response.setCharacterEncoding("UTF-8"); //this line solved the problem
//returnObject is an JSON object
response.getWriter().write(returnObject.toString());
I hope this helps someone, who tries to implement autocompletion using a servlet and the geonames Java client