use of com.yahoo.elide.core.utils.coerce.converters.Serde in project elide by yahoo.
the class WeekSerdeTest method testDeserializeDateInvalidFormat.
@Test
public void testDeserializeDateInvalidFormat() {
String dateInString = "January-2020-01";
Serde serde = new Week.WeekSerde();
assertThrows(DateTimeParseException.class, () -> serde.deserialize(dateInString));
}
use of com.yahoo.elide.core.utils.coerce.converters.Serde in project elide by yahoo.
the class WeekSerdeTest method testDateSerialize.
@Test
public void testDateSerialize() {
LocalDateTime localDate = LocalDateTime.of(2020, java.time.Month.of(01), 05, 00, 00, 00);
Week expectedDate = new Week(localDate);
Serde serde = new Week.WeekSerde();
Object actual = serde.serialize(expectedDate);
assertEquals("2020-01-05", actual);
}
use of com.yahoo.elide.core.utils.coerce.converters.Serde in project elide by yahoo.
the class WeekSerdeTest method testDeserializeOffsetDateTimeNotSunday.
@Test
public void testDeserializeOffsetDateTimeNotSunday() {
OffsetDateTime dateTime = OffsetDateTime.of(2020, 1, 6, 0, 0, 0, 0, ZoneOffset.UTC);
Serde serde = new Week.WeekSerde();
assertThrows(IllegalArgumentException.class, () -> serde.deserialize(dateTime));
}
use of com.yahoo.elide.core.utils.coerce.converters.Serde in project elide by yahoo.
the class YearSerdeTest method testDateDeserialize.
@Test
public void testDateDeserialize() {
LocalDateTime localDate = LocalDateTime.of(2020, java.time.Month.of(01), 01, 00, 00, 00);
Year expectedDate = new Year(localDate);
Serde serde = new Year.YearSerde();
Object actualDate = serde.deserialize("2020");
assertEquals(expectedDate, actualDate);
}
use of com.yahoo.elide.core.utils.coerce.converters.Serde in project elide by yahoo.
the class Elide method registerCustomSerde.
protected void registerCustomSerde() {
Injector injector = elideSettings.getDictionary().getInjector();
Set<Class<?>> classes = registerCustomSerdeScan();
for (Class<?> clazz : classes) {
if (!Serde.class.isAssignableFrom(clazz)) {
log.warn("Skipping Serde registration (not a Serde!): {}", clazz);
continue;
}
Serde serde = (Serde) injector.instantiate(clazz);
injector.inject(serde);
ElideTypeConverter converter = clazz.getAnnotation(ElideTypeConverter.class);
Class baseType = converter.type();
registerCustomSerde(baseType, serde, converter.name());
for (Class type : converter.subTypes()) {
if (!baseType.isAssignableFrom(type)) {
throw new IllegalArgumentException("Mentioned type " + type + " not subtype of " + baseType);
}
registerCustomSerde(type, serde, converter.name());
}
}
}
Aggregations