| 23 | import java.lang.reflect.Type; |
| 24 | |
| 25 | public class MoshiEncoder implements Encoder, JsonEncoder { |
| 26 | |
| 27 | private final Moshi moshi; |
| 28 | |
| 29 | public MoshiEncoder() { |
| 30 | this.moshi = new Moshi.Builder().build(); |
| 31 | } |
| 32 | |
| 33 | public MoshiEncoder(Moshi moshi) { |
| 34 | this.moshi = moshi; |
| 35 | } |
| 36 | |
| 37 | public MoshiEncoder(Iterable<JsonAdapter<?>> adapters) { |
| 38 | this(MoshiFactory.create(adapters)); |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public void encode(Object object, Type bodyType, RequestTemplate template) { |
| 43 | JsonAdapter<Object> jsonAdapter = moshi.adapter(bodyType).indent(" "); |
| 44 | template.body(jsonAdapter.toJson(object)); |
| 45 | } |
| 46 | } |
nothing calls this directly
no outgoing calls
no test coverage detected