-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
148 additions
and
178 deletions.
There are no files selected for viewing
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
31 changes: 13 additions & 18 deletions
31
src/main/java/org/komamitsu/retrofit/converter/msgpack/MessagePackRequestBodyConverter.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,24 @@ | ||
package org.komamitsu.retrofit.converter.msgpack; | ||
|
||
import com.fasterxml.jackson.databind.ObjectWriter; | ||
import java.io.IOException; | ||
import okhttp3.MediaType; | ||
import okhttp3.RequestBody; | ||
import retrofit2.Converter; | ||
|
||
import java.io.IOException; | ||
|
||
class MessagePackRequestBodyConverter<T> | ||
implements Converter<T, RequestBody> | ||
{ | ||
private static final MediaType MEDIA_TYPE = MediaType.parse("application/x-msgpack; charset=UTF-8"); | ||
class MessagePackRequestBodyConverter<T> implements Converter<T, RequestBody> { | ||
private static final MediaType MEDIA_TYPE = | ||
MediaType.parse("application/x-msgpack; charset=UTF-8"); | ||
|
||
private final ObjectWriter adapter; | ||
private final ObjectWriter adapter; | ||
|
||
MessagePackRequestBodyConverter(ObjectWriter adapter) | ||
{ | ||
this.adapter = adapter; | ||
} | ||
MessagePackRequestBodyConverter(ObjectWriter adapter) { | ||
this.adapter = adapter; | ||
} | ||
|
||
@Override | ||
public RequestBody convert(T value) | ||
throws IOException | ||
{ | ||
byte[] bytes = adapter.writeValueAsBytes(value); | ||
return RequestBody.create(MEDIA_TYPE, bytes); | ||
} | ||
@Override | ||
public RequestBody convert(T value) throws IOException { | ||
byte[] bytes = adapter.writeValueAsBytes(value); | ||
return RequestBody.create(MEDIA_TYPE, bytes); | ||
} | ||
} |
29 changes: 12 additions & 17 deletions
29
src/main/java/org/komamitsu/retrofit/converter/msgpack/MessagePackResponseBodyConverter.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,22 @@ | ||
package org.komamitsu.retrofit.converter.msgpack; | ||
|
||
import com.fasterxml.jackson.databind.ObjectReader; | ||
import okhttp3.ResponseBody; | ||
import retrofit2.Converter; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import okhttp3.ResponseBody; | ||
import retrofit2.Converter; | ||
|
||
class MessagePackResponseBodyConverter<T> | ||
implements Converter<ResponseBody, T> | ||
{ | ||
private final ObjectReader adapter; | ||
class MessagePackResponseBodyConverter<T> implements Converter<ResponseBody, T> { | ||
private final ObjectReader adapter; | ||
|
||
MessagePackResponseBodyConverter(ObjectReader adapter) | ||
{ | ||
this.adapter = adapter; | ||
} | ||
MessagePackResponseBodyConverter(ObjectReader adapter) { | ||
this.adapter = adapter; | ||
} | ||
|
||
@Override | ||
public T convert(ResponseBody value) throws IOException | ||
{ | ||
try (InputStream in = value.byteStream()) { | ||
return adapter.readValue(in); | ||
} | ||
@Override | ||
public T convert(ResponseBody value) throws IOException { | ||
try (InputStream in = value.byteStream()) { | ||
return adapter.readValue(in); | ||
} | ||
} | ||
} |
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