-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1187 from ericenns/hotfix/correct-rest-api-date-f…
…ields Hotfix/correct rest api date fields
- Loading branch information
Showing
5 changed files
with
81 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...main/java/ca/corefacility/bioinformatics/irida/web/controller/api/json/TimestampJson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ca.corefacility.bioinformatics.irida.web.controller.api.json; | ||
|
||
import java.io.IOException; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
|
||
import org.apache.commons.lang3.time.DateUtils; | ||
|
||
/** | ||
* Serialization class for java Date objects. We use DATETIME types for storing | ||
* our timestamps in mysql. DATETIME only stores at seconds precision by | ||
* default. In the REST api when we create an object the timestamps will have | ||
* milliseconds precision but on subsequent fetchs the timestamps will only have | ||
* seconds precision. This enforces the timestamp fields to only ever have | ||
* seconds precision. | ||
*/ | ||
public class TimestampJson { | ||
|
||
/** | ||
* Default serializer for {@link Date} objects. | ||
*/ | ||
public static class TimestampSerializer extends StdSerializer<Date> { | ||
|
||
public TimestampSerializer() { | ||
super(Date.class); | ||
} | ||
|
||
@Override | ||
public void serialize(Date value, JsonGenerator gen, SerializerProvider provider) throws IOException { | ||
gen.writeNumber(DateUtils.truncate(value, Calendar.SECOND).getTime()); | ||
} | ||
|
||
} | ||
} |