Skip to content

Instantly share code, notes, and snippets.

@GulajavaMinistudio
Created November 18, 2015 04:55
Show Gist options
  • Save GulajavaMinistudio/4e9e96c3b90686cc943a to your computer and use it in GitHub Desktop.
Save GulajavaMinistudio/4e9e96c3b90686cc943a to your computer and use it in GitHub Desktop.
JacksonJrRequestBodyConverter class for making Request Body in Converter.Factory
package gk.retrofittest;
import com.fasterxml.jackson.jr.ob.JSON;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.RequestBody;
import java.io.IOException;
import retrofit.Converter;
/**
* Created by Gulajava Ministudio on 11/18/15.
*/
public class JacksonJrRequestBodyConverter<T> implements Converter<T, RequestBody> {
private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8");
protected static final String PROTOCOL_CHARSET = "utf-8";
@Override
public RequestBody convert(T value) throws IOException {
byte[] bytes = JSON.std.asBytes(value);
return RequestBody.create(MEDIA_TYPE, bytes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment