com.alibaba.fastjson.serializer.SimpleDateFormatSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fastjson Show documentation
Show all versions of fastjson Show documentation
Fastjson is a JSON processor (JSON parser + JSON generator) written in Java
The newest version!
package com.alibaba.fastjson.serializer;
import java.io.IOException;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.Date;
public class SimpleDateFormatSerializer
implements ObjectSerializer {
private final String pattern;
public SimpleDateFormatSerializer(String pattern) {
this.pattern = pattern;
}
public void write(JSONSerializer serializer,
Object object,
Object fieldName,
Type fieldType,
int features) throws IOException {
if (object == null) {
serializer.out.writeNull();
return;
}
Date date = (Date) object;
SimpleDateFormat format = new SimpleDateFormat(pattern);
String text = format.format(date);
serializer.write(text);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy