Java API date returned in odd format

LabKey Support Forum (Inactive)
Java API date returned in odd format dennisw  2017-05-24 12:10
Status: Closed
 
When making a Java API call to retrieve a dataset, I'm seeing dates returned in this format when using the standard call (as shown in Export > Java API):

for (Map<String, Object> row : response.getRows())
                    {
                         System.out.println(row);
                    }

..... MMDT={"value":Wed May 23 00:00:00 EDT 2007} .....

In the study's datasets_metadata.xml, the column is defined as:

<column columnName="MMDT">
    <datatype>timestamp</datatype>
        <columnTitle>MMTT Date</columnTitle>
        <rangeURI>http://www.w3.org/2001/XMLSchema#dateTime</rangeURI>
</column>

Is there any reason it would be appearing in this format as opposed to an ISO format?
 
 
adam responded:  2017-05-24 12:21
System.out.println(row) will call toString() on row... which will call toString() on each map entry which will call toString() on each object value. The value you're seeing is the default Java Date.toString(). Can you inspect the individual objects and confirm that the API is giving you Date objects? If so, the API is doing what its supposed to do... translating each JSON value into the appropriate Java object. If you want to display Dates in a specific format your code will need to implement this via DateFormat or similar.

Adam
 
dennisw responded:  2017-05-24 12:26
That's a good point. I was trying to store the metadata for the column and the field values as separate objects (with a String for the value) and then join them up later, but maybe I need to evaluate the column type at each field as I'm reading it. Will let you know if that helps.