Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6922665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:26:08+00:00 2026-05-27T10:26:08+00:00

I have a data entity that I use in two ways, I populate a

  • 0

I have a data entity that I use in two ways, I populate a table with some of its data when the page loads, and when you click a row of that column, I AJAX up the details of that item and display them in form fields. I’m using Spring-Roo generated REST endpoints on the server side, and Backbone.js on the client.

When the table loads, date fields have the format I expect, coming straight out of my MySQL database (“yyyy-MM-dd”). When I get my AJAX data, date fields come to me as Unix time values (e.g. “1323666000000”).

I can convert that on the client side, but that’s stupid. Any idea how I can get my json controller to not do this?

I’ve tried pushing those fields into my .java file and messing with the @DateTimeFormat annotation, but I can’t see that makes any difference.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:26:08+00:00Added an answer on May 27, 2026 at 10:26 am

    You can transform the date to any format you want for your JSON response.

    In your case, you’ve been using the default JSON date transformer all the time for the java.util.Date type fields. This is basically what gets generated for you by the Spring Roo. Take a look and in your *_Roo_Json aspects and you will find smth. like this:

    public java.lang.String PizzaOrder.toJson() {
        return new JSONSerializer().exclude("*.class").serialize(this);
    }
    

    Such an implementation uses the flexjson.transformer.BasicDateTransformer class to transform the date for you. It is implemented like this:

    public class BasicDateTransformer extends AbstractTransformer {
        public void transform(Object object) {
            getContext().write(String.valueOf(((Date) object).getTime()));
        }
    }
    

    What you want is to use a different, more powerfull transformer. Luckily it comes with your Roo and it’s called flexjson.transformer.DateTransformer. Now, in order to format your dates properly, just replace the default with the new transformer e.g. like this:

    public java.lang.String PizzaOrder.toJson() {
        return new JSONSerializer().exclude("*.class")
                 .transform(new DateTransformer("MM/dd/yyyy"), Date.class)
                 .serialize(this);
    }
    

    That’s all 🙂

    Know that you may also apply different Date (and not only) transformations for different fields like this:

    transform(new DateTransformer("MM/dd/yyyy"), "person.birthday")
    

    For more info about the flexjson take a look at FLEXJSON project page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use ADO.NET Entity-Framework, I have a page that is data-bound to an entity
I have an Entity Data Model that I have created, and its pulling in
I have a page where I use two ASP DetailsView controls to render data
I use Entity Framework to access my SQL data. I have some constraints in
In my core data model I have a Person entity that has a to
I have an entity in core data that has 2 Attributes. One that is
I have an NSTreeController that manages an entity is a core data model and
I have set up a Core Data model that includes an entity, Item with
I have a Core Data entity which needs a gender property. I just need
I have an Core Data Entity with a number of attributes, which include amount(float),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.