Initial Commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package net.locusworks.common.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
|
||||
/**
|
||||
* Class to serialize a date object into a json string value <br>
|
||||
* This serializer will convert date objects to their timestamp representation <br>
|
||||
* For example the below code:
|
||||
* <pre>
|
||||
* {@code @JsonSerialize(using=DateTimeStampSerializer.class)
|
||||
* private Date purgeEndDate;
|
||||
* }
|
||||
* </pre>
|
||||
* Will specify to use this serializer class when the {@code purgeEndDate} is encountered when converting to json
|
||||
* and will try to convert the date object to its timestamp equivalent
|
||||
* @author Isaac Parenteau
|
||||
* @date 02/15/2018
|
||||
* @version 1.0
|
||||
* @see com.fasterxml.jackson.databind.annotation.JsonSerialize
|
||||
* @see com.fasterxml.jackson.databind.ser.std.StdSerializer
|
||||
*/
|
||||
public class DateTimeStampSerializer extends StdSerializer<Date> {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4753139740916300831L;
|
||||
|
||||
public DateTimeStampSerializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public DateTimeStampSerializer(Class<Date> t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(Date date, JsonGenerator generator, SerializerProvider provider) throws IOException {
|
||||
generator.writeNumber(date.getTime());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user