global.maplink.json.JsonMapper Maven / Gradle / Ivy
The newest version!
package global.maplink.json;
import global.maplink.NoImplementationFoundException;
import java.util.List;
import java.util.ServiceLoader;
import java.util.stream.StreamSupport;
import static java.nio.charset.StandardCharsets.UTF_8;
public interface JsonMapper {
T fromJson(byte[] data, Class type);
default T fromJson(String data, Class type) {
return fromJson(data.getBytes(), type);
}
List fromJsonList(byte[] data, Class type);
default List fromJsonList(String data, Class type) {
return fromJsonList(data.getBytes(), type);
}
byte[] toJson(T object);
default String toJsonString(T object) {
return new String(toJson(object), UTF_8);
}
static JsonMapper loadDefault() {
ServiceLoader load = ServiceLoader.load(JsonMapper.class);
return StreamSupport.stream(load.spliterator(), false)
.findFirst()
.orElseThrow(() -> new NoImplementationFoundException(JsonMapper.class));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy