All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.abubusoft.kripton.retrofit2.KriptonBinderRequestBodyCollectionConverter Maven / Gradle / Ivy

There is a newer version: 8.2.0-rc.4
Show newest version
package com.abubusoft.kripton.retrofit2;

import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.util.Collection;

import com.abubusoft.kripton.BinderContext;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import okio.Buffer;
import retrofit2.Converter;

final class KriptonBinderRequestBodyCollectionConverter implements Converter {
	private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8");

	private BinderContext binderContext;

	private Class beanClazz;

	//private Class clazz;

	KriptonBinderRequestBodyCollectionConverter(BinderContext binderContext, ParameterizedType collectionType) {
		this.binderContext=binderContext;
		//this.clazz = (Class) collectionType.getRawType();
		this.beanClazz = (Class) collectionType.getActualTypeArguments()[0];
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public RequestBody convert(T value) throws IOException {
		Buffer buffer = new Buffer();	
		
		try {			
			binderContext.serializeCollection((Collection)value, beanClazz,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