|
From: Raphael S. <rap...@gm...> - 2013-01-03 14:02:42
|
Hi!
I just found out what was wrong.
I had to add to my MANIFEST.MF the dependencies
to org.codehaus.jackson.jackson-mapper-asl and other jackson libraries.
I think that by the time my ear was loaded by jboss, the jackson module
wasn't. So, @JsonSerialize and @JsonDeserialize annotations were just
ignored.
As soon as I added the dependencies to the manifest, it all worked just
fine.
On Tue, Dec 18, 2012 at 6:50 PM, Raphael Silva <rap...@gm...>wrote:
> Hi guys,
>
> I have a class defined as this:
> -------
> @IgnoreMediaTypes(MediaType.APPLICATION_JSON)
> public class Processo implements Serializable {
>
> private Date dataInclusao;
>
> @JsonSerialize(using = CustomJsonDateSerializer.class)
> public Date getDataInclusao() {
> return dataInclusao;
> }
>
> /**
> * @param dataInclusao the dataInclusao to set
> */
> @JsonDeserialize(using = CustomJsonDateDeserializer.class)
> public void setDataInclusao(final Date dataInclusao) {
> this.dataInclusao = dataInclusao;
> }
> -------
> My Service is defined as it follows:
> -----
> @GET
> @Path("/{idProcessoBpmn}")
> @Produces(MediaType.APPLICATION_JSON)
> public Response getProcesso(@PathParam("idProcessoBpmn") final String
> idProcessoBpmn) {
> try {
> Processo processo =
> deploymentService.getDeploymentByProcessId(idProcessoBpmn);
> return
> Response.status(HttpResponseCodes.SC_OK).entity(processo).build();
> } catch (Exception e) {
> LOG.error(e.getMessage(), e);
> return
> Response.status(HttpResponseCodes.SC_INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
> }
> }
> -----
>
> My CustomJsonDateDeserializer and CustomJsonDateSerializer classes define
> a SimpleDateFormat for the JSON.
> -------
> @Override
> public void serialize(Date date, JsonGenerator jsonGenerator,
> SerializerProvider serializerProvider) throws IOException,
> JsonProcessingException {
> SimpleDateFormat dateFormat = new
> SimpleDateFormat(JsonMask.DATA_FORMAT);
> String dateString = dateFormat.format(date);
> jsonGenerator.writeString(dateString);
> }
>
> -----
> @Override
> public Date deserialize(JsonParser jsonparser, DeserializationContext
> deserializationcontext) throws IOException, JsonProcessingException {
> SimpleDateFormat format = new
> SimpleDateFormat(JsonMask.DATA_FORMAT);
> String date = jsonparser.getText();
> try {
> return format.parse(date);
> } catch (ParseException e) {
> throw new RuntimeException(e);
> }
>
> }
> ----
>
>
> I'm using jboss-as-7.2.0.Alpha1-SNAPSHOT and I have
> updated org\jboss\resteasy\resteasy-jackson-provider module to version
> 2.3.5.
>
> In my unit test, using MockHttpRequest and MockHttpResponse, it worked
> fine.
> My service returns a JSON (Processo) like this:
> {"id":1, "dataInclusao":"18/12/2012 18:44:37"}
>
> But when I access the service through a browser the json is different. The
> date parameter is not formatted:
> {"id":335,"dataInclusao":1354586400000}
>
> My serializer and deserializer methods are not called when I access the
> service running in jboss.
>
> Am I missing something? Is there any jackson configuration that I must do?
>
> Thanks in advance!
>
>
>
|