Search in sources :

Example 11 with Serde

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));
}
Also used : Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) Test(org.junit.jupiter.api.Test)

Example 12 with Serde

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) Week(com.yahoo.elide.datastores.aggregation.timegrains.Week) Test(org.junit.jupiter.api.Test)

Example 13 with Serde

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));
}
Also used : Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) OffsetDateTime(java.time.OffsetDateTime) Test(org.junit.jupiter.api.Test)

Example 14 with Serde

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) Year(com.yahoo.elide.datastores.aggregation.timegrains.Year) Test(org.junit.jupiter.api.Test)

Example 15 with Serde

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());
        }
    }
}
Also used : Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) Injector(com.yahoo.elide.core.dictionary.Injector) ElideTypeConverter(com.yahoo.elide.core.utils.coerce.converters.ElideTypeConverter)

Aggregations

Serde (com.yahoo.elide.core.utils.coerce.converters.Serde)62 Test (org.junit.jupiter.api.Test)59 LocalDateTime (java.time.LocalDateTime)34 OffsetDateTime (java.time.OffsetDateTime)12 Timestamp (java.sql.Timestamp)10 Time (com.yahoo.elide.datastores.aggregation.timegrains.Time)6 ISOWeek (com.yahoo.elide.datastores.aggregation.timegrains.ISOWeek)5 Quarter (com.yahoo.elide.datastores.aggregation.timegrains.Quarter)5 Week (com.yahoo.elide.datastores.aggregation.timegrains.Week)5 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)4 Hour (com.yahoo.elide.datastores.aggregation.timegrains.Hour)4 Minute (com.yahoo.elide.datastores.aggregation.timegrains.Minute)4 Month (com.yahoo.elide.datastores.aggregation.timegrains.Month)4 Second (com.yahoo.elide.datastores.aggregation.timegrains.Second)4 Year (com.yahoo.elide.datastores.aggregation.timegrains.Year)4 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 Injector (com.yahoo.elide.core.dictionary.Injector)1 AccessibleObject (com.yahoo.elide.core.type.AccessibleObject)1 Field (com.yahoo.elide.core.type.Field)1 Method (com.yahoo.elide.core.type.Method)1