سؤال

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 contain 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 notice 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?

هل كانت مفيدة؟

المحلول 2

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 –

نصائح أخرى

You didn't specify name of the annotation attribute. By default annotations with empty names are not deserialized. For further references take a look at the Apache docs.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top