All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.firefly.utils.json.serializer.DateSerializer Maven / Gradle / Ivy

There is a newer version: 5.0.2
Show newest version
package com.firefly.utils.json.serializer;

import static com.firefly.utils.json.JsonStringSymbol.QUOTE;

import java.io.IOException;
import java.util.Date;

import com.firefly.utils.json.JsonWriter;
import com.firefly.utils.json.Serializer;
import com.firefly.utils.time.SafeSimpleDateFormat;

public class DateSerializer implements Serializer {
	
	private SafeSimpleDateFormat safeSimpleDateFormat = SafeSimpleDateFormat.defaultDateFormat;
	
	public DateSerializer() {}

	public DateSerializer(String datePattern) {
		this.safeSimpleDateFormat = new SafeSimpleDateFormat(datePattern);
	}

	@Override
	public void convertTo(JsonWriter writer, Object obj) throws IOException {
		writer.write(QUOTE + safeSimpleDateFormat.format((Date) obj) + QUOTE);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy