You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.1 KiB
29 lines
1.1 KiB
|
3 years ago
|
package com.bx.imcommon.serializer;
|
||
|
3 years ago
|
|
||
|
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||
|
|
import com.fasterxml.jackson.core.JsonToken;
|
||
|
|
import com.fasterxml.jackson.core.type.WritableTypeId;
|
||
|
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
||
|
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||
|
|
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
||
|
|
|
||
|
|
import java.io.IOException;
|
||
|
|
import java.util.Date;
|
||
|
|
|
||
|
|
public class DateToLongSerializer extends JsonSerializer<Date> {
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void serialize(Date date, JsonGenerator jsonGenerator,
|
||
|
|
SerializerProvider serializerProvider) throws IOException {
|
||
|
|
jsonGenerator.writeNumber(date.getTime());
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void serializeWithType(Date value, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException {
|
||
|
|
WritableTypeId typeIdDef = typeSer.writeTypePrefix(gen,
|
||
|
|
typeSer.typeId(value, JsonToken.VALUE_STRING));
|
||
|
|
serialize(value, gen, serializers);
|
||
|
|
typeSer.writeTypeSuffix(gen, typeIdDef);
|
||
|
|
}
|
||
|
|
}
|