com.abubusoft.kripton.retrofit2.KriptonRequestBodyConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kripton-retrofit-converter Show documentation
Show all versions of kripton-retrofit-converter Show documentation
Kripton adapter for Retrofit library
package com.abubusoft.kripton.retrofit2;
import java.io.IOException;
import com.abubusoft.kripton.BinderContext;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okio.Buffer;
import retrofit2.Converter;
final class KriptonRequestBodyConverter implements Converter {
private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8");
private BinderContext binderContext;
KriptonRequestBodyConverter(BinderContext binderContext, Class clazz) {
this.binderContext = binderContext;
}
@Override
public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
try {
binderContext.serialize(value, buffer.outputStream());
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
buffer.close();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy