Skip to main content

RePost question Glassfish 4 JAXRS UTF-8 consomption

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
bsdmonkey
Offline
Joined: 2007-01-26

Worth saying that this works perfectly under WildFly 8.0 but it's a show stopper under Glassfish 4.0:

Am running Jax-RS end-points on Glassfish 4.0 with Backbone MarionetteJS HTML client (uses JQuery internally) so far everything works correctly but when I POST a JSON payload with arabic content it hits the database (Postgres) with wrong encoding. If I directly modify the database row content with arabic content it gets displayed correctly.

Postgres 9.2 database is created with:

WITH ENCODING = 'UTF8'
In glassfish-resources I have:

In glassfish-web.xml I have:


In the JAX-RS Resource I have:

@POST
@Consumes(MediaType.APPLICATION_JSON + ";charset=UTF-8")
public Response createCabinet(@Context UriInfo uriInfo, Cabinet cab) {
System.out.println(cab);
Cabinet createdCab = cabinetService.createCabinet(cab);
URI uri = uriInfo.getAbsolutePathBuilder().path(createdCab.getId()).build();
return Response.created(uri).build();
}

@GET
@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
public Response getCabinets(@QueryParam("from") @DefaultValue("0") int from,
@QueryParam("to") @DefaultValue("10") int to) {
List cabinets = cabinetService.getCabinets(from, to);
GenericEntity> entity = new GenericEntity>(cabinets){};
return Response.ok(entity).build();
}

SO question: http://stackoverflow.com/questions/22538619/glassfish-4-jaxrs-utf-8-cons...

Thanks in advance,
--Daoud.