
com.eventsourcing.layout.Serialization Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eventsourcing-layout Show documentation
Show all versions of eventsourcing-layout Show documentation
Event capture and querying framework for Java
/**
* Copyright (c) 2016, All Contributors (see CONTRIBUTORS file)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.eventsourcing.layout;
import java.util.HashMap;
public abstract class Serialization {
protected HashMap> serializers = new HashMap<>();
protected HashMap> deserializers = new HashMap<>();
@SuppressWarnings("unchecked")
public Serializer getSerializer(H typeHandler) {
Serializer s = (Serializer) serializers.get(typeHandler);
if (s == null) {
throw new RuntimeException("No " + getClass().getName() + " serializer for " + typeHandler.getClass() + " has " +
"been found");
}
return s;
}
@SuppressWarnings("unchecked")
public Deserializer getDeserializer(H typeHandler) {
Deserializer ds = (Deserializer) deserializers.get(typeHandler);
if (ds == null) {
throw new RuntimeException("No " + getClass().getName() + " deserializer for " + typeHandler.getClass() + " has " +
"been found");
}
return ds;
}
public void addSerializer(H typeHandler, Serializer, H> serializer) {
serializers.put(typeHandler, serializer);
if (!serializers.containsKey(typeHandler)) {
throw new RuntimeException("Can't store type handler " + typeHandler);
}
}
public void addDeserializer(H typeHandler, Deserializer, H> deserializer) {
deserializers.put(typeHandler, deserializer);
if(!deserializers.containsKey(typeHandler)) {
throw new RuntimeException("Can't store type handler " + typeHandler);
}
}
public abstract ObjectSerializer getSerializer(Class> klass);
public ObjectDeserializer getDeserializer(Class> klass) {
return getDeserializer(klass, false);
}
public abstract ObjectDeserializer getDeserializer(Class> klass, boolean allowReadonly);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy