Created
November 18, 2015 04:55
-
-
Save GulajavaMinistudio/4e9e96c3b90686cc943a to your computer and use it in GitHub Desktop.
JacksonJrRequestBodyConverter class for making Request Body in Converter.Factory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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