use of com.yahoo.elide.core.utils.coerce.converters.Serde in project elide by yahoo.
the class YearSerdeTest method testDeserializeDateInvalidFormat.
@Test
public void testDeserializeDateInvalidFormat() {
String dateInString = "January";
Serde serde = new Year.YearSerde();
assertThrows(DateTimeParseException.class, () -> serde.deserialize(dateInString));
}
use of com.yahoo.elide.core.utils.coerce.converters.Serde in project elide by yahoo.
the class CoerceUtilTest method testDateToTimestamp.
@Test
public void testDateToTimestamp() {
String dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'";
TimeZone tz = TimeZone.getTimeZone("UTC");
Serde oldDateSerde = CoerceUtil.lookup(Date.class);
Serde oldTimestampSerde = CoerceUtil.lookup(java.sql.Timestamp.class);
Serde timestampSerde = new ISO8601DateSerde(dateFormat, tz, java.sql.Timestamp.class);
CoerceUtil.register(Date.class, new ISO8601DateSerde(dateFormat, tz));
CoerceUtil.register(java.sql.Timestamp.class, timestampSerde);
Date date = new Date();
Timestamp timestamp = CoerceUtil.coerce(date, Timestamp.class);
assertEquals(date.getTime(), timestamp.getTime());
CoerceUtil.register(Date.class, oldDateSerde);
CoerceUtil.register(java.sql.Timestamp.class, oldTimestampSerde);
}
Aggregations