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

dsl_json.java.sql.TimestampDslJsonConverter Maven / Gradle / Ivy

There is a newer version: 1.10.0
Show newest version
package dsl_json.java.sql;

import com.dslplatform.json.*;

import java.io.IOException;
import java.sql.Timestamp;
import java.time.OffsetDateTime;
import java.time.ZoneId;

public class TimestampDslJsonConverter implements Configuration {
	@Override
	public void configure(DslJson json) {
		json.registerReader(java.sql.Timestamp.class, new JsonReader.ReadObject() {
			@Nullable
			@Override
			public Timestamp read(JsonReader reader) throws IOException {
				return reader.wasNull() ? null : java.sql.Timestamp.from(JavaTimeConverter.deserializeDateTime(reader).toInstant());
			}
		});
		json.registerWriter(java.sql.Timestamp.class, new JsonWriter.WriteObject() {
			@Override
			public void write(JsonWriter writer, @Nullable java.sql.Timestamp value) {
				if (value == null) writer.writeNull();
				else JavaTimeConverter.serialize(OffsetDateTime.ofInstant(value.toInstant(), ZoneId.systemDefault()), writer);
			}
		});
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy