com.yahoo.elide.Serdes Maven / Gradle / Ivy
/*
* Copyright 2023, the original author or authors.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide;
import com.yahoo.elide.core.utils.coerce.converters.EpochToDateConverter;
import com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde;
import com.yahoo.elide.core.utils.coerce.converters.InstantSerde;
import com.yahoo.elide.core.utils.coerce.converters.OffsetDateTimeSerde;
import com.yahoo.elide.core.utils.coerce.converters.Serde;
import com.yahoo.elide.core.utils.coerce.converters.TimeZoneSerde;
import com.yahoo.elide.core.utils.coerce.converters.URLSerde;
import java.net.URL;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TimeZone;
import java.util.function.Consumer;
/**
* Contains serializers and deserializers implemented using {@link Serde}.
*
* Use the static factory {@link #builder()} method to prepare an instance.
*
*/
public class Serdes extends LinkedHashMap {
private static final long serialVersionUID = 1L;
/**
* Returns a mutable {@link SerdesBuilder} for building {@link Serdes}.
*
* @return the builder
*/
public static SerdesBuilder builder() {
return new SerdesBuilder();
}
/**
* Returns a builder with the current values.
*
* @return the builder to mutate
*/
public SerdesBuilder mutate() {
return builder().entries(
entries -> this.entrySet().stream().forEach(entry -> entries.put(entry.getKey(), entry.getValue())));
}
/**
* A mutable builder for building {@link Serdes}.
*/
public static class SerdesBuilder extends SerdesBuilderSupport {
public Serdes build() {
Serdes serdes = new Serdes();
serdes.putAll(this.entries);
return serdes;
}
@Override
public SerdesBuilder self() {
return this;
}
}
public abstract static class SerdesBuilderSupport {
protected Map, Serde, ?>> entries = new LinkedHashMap<>();
public abstract S self();
public S entries(Consumer