本文整理汇总了Java中retrofit.converter.Converter类的典型用法代码示例。如果您正苦于以下问题:Java Converter类的具体用法?Java Converter怎么用?Java Converter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Converter类属于retrofit.converter包,在下文中一共展示了Converter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildRestAdapter
import retrofit.converter.Converter; //导入依赖的package包/类
/**
* Build RestAdapter for request
*
* @param interceptor - {@link Interceptor} for request (optional)
* @param converter - {@link Converter} for Request (optional)
* @return - {@link RestAdapter} used to create {@link PopdeemAPI}
*/
private RestAdapter buildRestAdapter(Interceptor interceptor, Converter converter) {
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.readTimeout(30, TimeUnit.SECONDS)
.connectTimeout(30, TimeUnit.SECONDS)
.addInterceptor(PD_API_KEY_INTERCEPTOR);
if (interceptor != null) {
builder.addInterceptor(interceptor);
}
OkHttpClient okHttpClient = builder.build();
RestAdapter.Builder adapterBuilder = new RestAdapter.Builder()
.setClient(new Ok3Client(okHttpClient))
.setEndpoint(PDAPIConfig.PD_API_ENDPOINT)
.setLogLevel(RestAdapter.LogLevel.FULL);
if (converter != null) {
adapterBuilder.setConverter(converter);
}
return adapterBuilder.build();
}
示例2: buildRestAdapter
import retrofit.converter.Converter; //导入依赖的package包/类
/**
* Build RestAdapter for request
*
* @param converter - {@link Converter} for Request (optional)
* @return - {@link RestAdapter} used to create {@link PDAbraAPI}
*/
private RestAdapter buildRestAdapter(Converter converter) {
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.readTimeout(30, TimeUnit.SECONDS)
.connectTimeout(30, TimeUnit.SECONDS)
.addInterceptor(PD_API_KEY_INTERCEPTOR);
Interceptor userInterceptor = getUserIdInterceptor();
if (userInterceptor != null) {
builder.addInterceptor(userInterceptor);
}
OkHttpClient okHttpClient = builder.build();
RestAdapter.Builder adapterBuilder = new RestAdapter.Builder()
.setClient(new Ok3Client(okHttpClient))
.setEndpoint(PDAbraConfig.ABRA_URL)
.setLogLevel(RestAdapter.LogLevel.FULL);
if (converter != null) {
adapterBuilder.setConverter(converter);
}
return adapterBuilder.build();
}
示例3: RestAdapter
import retrofit.converter.Converter; //导入依赖的package包/类
private RestAdapter(Server server, Client.Provider clientProvider, Executor httpExecutor,
Executor callbackExecutor, RequestInterceptor requestInterceptor, Converter converter,
Profiler profiler, ErrorHandler errorHandler, Log log, LogLevel logLevel)
{
this.server = server;
this.clientProvider = clientProvider;
this.httpExecutor = httpExecutor;
if (Platform.HAS_RX_JAVA && httpExecutor != null)
{
this.rxSupport = new RxSupport(httpExecutor);
}
else
{
this.rxSupport = null;
}
this.callbackExecutor = callbackExecutor;
this.requestInterceptor = requestInterceptor;
this.converter = converter;
this.profiler = profiler;
this.errorHandler = errorHandler;
this.log = log;
this.logLevel = logLevel;
}
示例4: getResponseDataConverter
import retrofit.converter.Converter; //导入依赖的package包/类
/**
* Returns a {@link Converter} configured to deserialize Robin entities.
*
* @return A converter.
*/
protected Converter getResponseDataConverter() {
Gson gson = new GsonBuilder()
// Set our naming policy to transform underscores <-> camelCase
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.registerTypeAdapter(DateTime.class, new JodaDateTimeAdapter())
.registerTypeAdapter(Invitable.class, new InvitableAdapter())
.registerTypeAdapter(Identifier.class, new IdentifierAdapter())
.registerTypeAdapterFactory(new RobinTypeAdapterFactory())
.registerTypeAdapter(Urn.class, new UrnAdapter())
.registerTypeHierarchyAdapter(Account.Reference.class, new AccountReferenceAdapter())
.serializeNulls()
.create();
return new GsonConverter(gson);
}
示例5: createConverter
import retrofit.converter.Converter; //导入依赖的package包/类
public static Converter createConverter() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return new JacksonConverter(objectMapper);
}
示例6: createConverter
import retrofit.converter.Converter; //导入依赖的package包/类
@Override
protected Converter createConverter() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return new JacksonConverter(objectMapper);
}
示例7: provideRetrofit
import retrofit.converter.Converter; //导入依赖的package包/类
@Provides
@Singleton
RestAdapter provideRetrofit(OkHttpClient okHttpClient, Converter converter, ErrorHandler errorHandler)
{
return new RestAdapter.Builder().setEndpoint(BASE_URL).setClient(new OkClient(okHttpClient)).setConverter(converter).setErrorHandler(errorHandler)
.setLogLevel(RestAdapter.LogLevel.FULL).build();
}
示例8: getConverter
import retrofit.converter.Converter; //导入依赖的package包/类
protected Converter getConverter() {
Gson gson = new GsonBuilder()
.registerTypeAdapter(Recipe.class, new RecipeDeserializer())
.registerTypeAdapter(Ingredient.class, new IngredientDeserializer())
.registerTypeAdapter(Element.class, new ElementDeserializer())
.create();
return new GsonConverter(gson);
}
示例9: provideAuthRestAdapter
import retrofit.converter.Converter; //导入依赖的package包/类
@Provides @ApplicationScope AuthService provideAuthRestAdapter(Client client, Converter converter) {
MockRestAdapter mockRestAdapter = MockRestAdapter.from(
new RestAdapter.Builder().setClient(client).setConverter(converter).setLogLevel(RestAdapter.LogLevel.BASIC).setLog(new RestAdapter.Log() {
@Override public void log(String message) {
Timber.d(message);
}
}).setEndpoint("https://alexrwegener.com/").build());
mockRestAdapter.setDelay(100);
return mockRestAdapter.create(AuthService.class, new MockAuthService());
}
示例10: getWeixinTemplateMessageAPI
import retrofit.converter.Converter; //导入依赖的package包/类
static public WeixinTemplateMessageAPI getWeixinTemplateMessageAPI(final Class clazz) {
final Logger logger = LoggerFactory.getLogger(clazz);
return new RestAdapter.Builder()
.setEndpoint("https://api.weixin.qq.com")
.setLogLevel(RestAdapter.LogLevel.FULL)
.setLog(new RestAdapter.Log() {
@Override
public void log(String message) {
logger.info(message);
}
})
.setConverter(new Converter() {
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException {
try {
return new JSONObject(IOUtils.toString(body.in(), Charsets.UTF_8));
} catch (Throwable t) {
logger.error("Hit an error!", t);
throw new ConversionException(t);
}
}
@Override
public TypedOutput toBody(Object object) {
TypedOutput typedOutput = new TypedString(object.toString());
return typedOutput;
}
})
.build().create(WeixinTemplateMessageAPI.class);
}
示例11: RetrofitError
import retrofit.converter.Converter; //导入依赖的package包/类
private RetrofitError(String url, Response response, Converter converter, Type successType, boolean networkError, Throwable exception) {
super(exception);
this.url = url;
this.response = response;
this.converter = converter;
this.successType = successType;
this.networkError = networkError;
}
示例12: RestAdapter
import retrofit.converter.Converter; //导入依赖的package包/类
private RestAdapter(Server server, Client.Provider clientProvider, Executor httpExecutor, Executor callbackExecutor, RequestInterceptor requestInterceptor, Converter converter, Profiler profiler, ErrorHandler errorHandler, Log log, LogLevel logLevel) {
this.server = server;
this.clientProvider = clientProvider;
this.httpExecutor = httpExecutor;
this.callbackExecutor = callbackExecutor;
this.requestInterceptor = requestInterceptor;
this.converter = converter;
this.profiler = profiler;
this.errorHandler = errorHandler;
this.log = log;
this.logLevel = logLevel;
}
示例13: setConverter
import retrofit.converter.Converter; //导入依赖的package包/类
/**
* The converter used for serialization and deserialization of objects.
*/
public Builder setConverter(Converter converter) {
if (converter == null) {
throw new NullPointerException("Converter may not be null.");
}
this.converter = converter;
return this;
}
示例14: getConverter
import retrofit.converter.Converter; //导入依赖的package包/类
public Converter getConverter()
{
if (mConverter == null)
{
mConverter = new CustomJacksonConverter(AutoMapper.getInstance());
}
return mConverter;
}
示例15: provideRestAdapter
import retrofit.converter.Converter; //导入依赖的package包/类
@Provides @Singleton
RestAdapter provideRestAdapter(Client client, Endpoint endpoint, Converter converter) {
return new RestAdapter.Builder()
.setClient(client)
.setEndpoint(endpoint)
.setConverter(converter)
.setLogLevel(RestAdapter.LogLevel.FULL)
.build();
}