本文整理匯總了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();
}