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

aQute.json.codec.DateHandler Maven / Gradle / Ivy

package aQute.json.codec;

import java.io.IOException;
import java.lang.reflect.Type;
import java.time.Instant;
import java.util.Date;
import java.util.Map;

public class DateHandler extends Handler {

	@Override
	public void encode(Encoder app, Object object, Map visited) throws IOException, Exception {
		Instant instant = Instant.ofEpochMilli(((Date) object).getTime());
		StringHandler.string(app, instant.toString());
	}

	@Override
	public Object decode(Decoder dec, String s) throws Exception {
		return new Date(Instant.parse(s).toEpochMilli());
	}

	@Override
	public Object decode(Decoder dec, Number s) throws Exception {
		return new Date(s.longValue());
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy