
dev.soffa.foundation.commons.Mapper Maven / Gradle / Ivy
package dev.soffa.foundation.commons;
import dev.soffa.foundation.error.NotImplementedException;
import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface Mapper {
T convert(Object data, Class type);
String fromXml(String xmlInput);
T fromXml(String xmlInput, String root, Class kind);
String serialize(Object data);
byte[] serializeAsBytes(Object data);
T deserialize(String data, Class type);
@SuppressWarnings("unchecked")
default T deserialize(String data, Type type) {
if (type instanceof Class>) {
return deserialize(data, (Class) type);
}
throw new NotImplementedException();
}
T deserialize(byte[] data, Class type);
T deserialize(InputStream source, Class type);
String prettyPrint(Object data);
void serializeToFile(Object content, File file);
Map deserializeMap(String input);
Map deserializeMap(InputStream input);
Map deserializeMap(InputStream input, Class type);
Map deserializeMap(String input, Class type);
T deserializeParametricType(String input, Class> rawType, Class>... parameterClasses);
List deserializeList(String input, Class type);
List deserializeList(InputStream input, Class type);
@SuppressWarnings("unchecked")
Map toMap(Object input, Class valueClass);
default Map toMap(Object input) {
if (input == null) {
return new HashMap<>();
}
return toMap(input, Object.class);
}
@SuppressWarnings("unchecked")
default T deserialize(byte[] payload, Type type) {
if (type instanceof Class>) {
return deserialize(payload, (Class) type);
}
throw new NotImplementedException();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy