jsondatestruts2struts2-json-plugin

org.apache.struts2.json.annotations.JSON doesn't show right format


My web application uses struts2-json-plugin-2.2.1.

I have an action that exposes an object loaded from DB (through Hibernate).

This object contains a java.util.Date field that is so annotated:

  @JSON(format = "dd-MM-yyyy")
  @Column(name = "DATA_CREAZIONE", nullable = false)
  public Date getDataCreazione() {
    return this.dataCreazione;
  }

Instead of getting:

"dataCreazione":"15-02-2013"

I get this:

"dataCreazione":"2013-02-15T16:51:06"

In debug, I noticed that the org.apache.struts2.json.JSONWriter class doesn't find any annotation over the getDataCreazione() method and that the proxy class is of the "$$_javassist" type rather than "$$EnhancerByCGLIB$$" as other cases...

In the same application I have a lot of this situations and the annotation works fine. I don't understand what is the problem (or the difference) with other classes.

Do you have any suggestions?


Solution

  • btw I confirm the origin of my problem. As I said before it resides in the proxy class that are used. In my case - if I load the object (through hibernate) then the proxy used is $$_javassist - if I get the object (through hibernate) then the object isn't proxied and then JSonWriter can resume the annotation -> so it's able to format as I have annotated –