Results 1 to 2 of 2

Thread: MySQL date field coming back as Unix time

  1. #1
    Join Date
    Oct 2011
    Posts
    17

    Default MySQL date field coming back as Unix time

    This is probably an easy one, but I can't find any docs about it.

    I'm getting dates out of my MySQL database as Unix timestamps. Formatting controls on my field definition don't seem to help.

    Code:
        @Column(name = "recovery_date", columnDefinition = "DATETIME")
        @Temporal(TemporalType.TIMESTAMP)
        @DateTimeFormat(style = "M")
        private Date recoveryDate;
    Yet that field comes out (in the output of the REST/JSON view that Roo built for me) as "1321385595"


    EDIT: Sigh. 47 views, 0 replies. Guess it's NOT an easy one?
    Last edited by danray0424; Nov 16th, 2011 at 02:32 PM.

  2. #2
    Join Date
    Oct 2011
    Posts
    17

    Default

    For future reference (and because nobody seems to answer any questions around here), the answer is to specify the date format in the JSON serializer configuration. Push-in the "toJson" method from Roo's json controller, and change it to say:
    Code:
    public String toJson() {
        return new JSONSerializer().exclude("*.class")
        		.transform(new DateTransformer("yyyy-MM-dd"), Date.class)
           		.serialize(this);
    }
    That .transform call specifies the format for all Date objects in the thing being serialized.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •