private ApiRetrofit() { super(); Gson gson = new GsonBuilder() .setLenient() .create(); //在构造方法中完成对Retrofit接口的初始化 mApi = new Retrofit.Builder() .baseUrl(MyApi.BASE_URL) .client(getClient()) .addConverterFactory(GsonConverterFactory.create(gson)) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build() .create(MyApi.class); }
@Signature(@Arg(value = "flags", optional = @Optional("0"))) public Memory __construct(Environment env, Memory... args) { int flags = args[0].toInteger(); if ((flags & SERIALIZE_PRETTY_PRINT) == SERIALIZE_PRETTY_PRINT) { builder.setPrettyPrinting(); } if ((flags & DESERIALIZE_LENIENT) == DESERIALIZE_LENIENT) { builder.setLenient(); } if ((flags & DESERIALIZE_AS_ARRAYS) == DESERIALIZE_AS_ARRAYS) { memoryDeserializer.setAssoc(true); } if (flags > 0) { gson = builder.create(); } return Memory.NULL; }
/** * Initialises the GSON layer. */ private void initGson() { gson = new GsonBuilder() .setLenient() //since all names in json starts upper case .create(); }
public RDFDatatypeJson(String uri) { this(uri, new GsonBuilder().setLenient().create()); }
public RDFDatatypeJson(String uri) { this(uri, new GsonBuilder().setLenient().create()); }
private FeedApi buildApi(OkHttpClient client) { return new Retrofit.Builder() .baseUrl(Mysplash.UNSPLASH_URL) .client(client) .addConverterFactory( GsonConverterFactory.create( new GsonBuilder().setLenient().create())) .build() .create((FeedApi.class)); }
private NotificationApi buildApi(OkHttpClient client) { return new Retrofit.Builder() .baseUrl(Mysplash.UNSPLASH_URL) .client(client) .addConverterFactory( GsonConverterFactory.create( new GsonBuilder().setLenient().create())) .build() .create((NotificationApi.class)); }
private BaiduLocationApi buildApi() { return new Retrofit.Builder() .baseUrl(BuildConfig.BAIDU_IP_LOCATION_BASE_URL) .addConverterFactory( GsonConverterFactory.create( new GsonBuilder().setLenient().create())) .client(buildClient()) .build() .create((BaiduLocationApi.class)); }
private CNWeatherApi buildApi() { return new Retrofit.Builder() .baseUrl(BuildConfig.CN_WEATHER_BASE_URL) .addConverterFactory( GsonConverterFactory.create( new GsonBuilder().setLenient().create())) .client(buildClient()) .build() .create((CNWeatherApi.class)); }
public static Retrofit build() { OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor(SeismicInterceptor.create()) .build(); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setLenient(); return new Retrofit.Builder() .baseUrl(API_URL) .client(okHttpClient) .addConverterFactory(GsonConverterFactory.create(gsonBuilder.create())) .build(); }
public static IGsonFactory2 create() { return create(new GsonBuilder().setLenient().create()); }
private Retrofit provideRetrofit(OkHttpClient okHttpClient) { Gson gson = new GsonBuilder() .setLenient() .registerTypeAdapterFactory(new Adapter()) .create(); return new Retrofit.Builder() .baseUrl(baseUrl) .addConverterFactory(GsonConverterFactory.create(gson)) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .client(okHttpClient) .build(); }
public BaseApiImpl(String baseUrl) { retrofitBuilder.addConverterFactory(ScalarsConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create(new GsonBuilder() .setLenient() .create() )) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .client(httpBuilder.addInterceptor(getLoggerInterceptor()).build()) .baseUrl(baseUrl); }
public AccuWeatherService() { OkHttpClient client = getClientBuilder() .addInterceptor(new GzipInterceptor()) // .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)) .build(); client.dispatcher().setMaxRequestsPerHost(1); this.api = new Retrofit.Builder() .baseUrl(BuildConfig.ACCU_WEATHER_BASE_URL) .addConverterFactory(GsonConverterFactory.create( new GsonBuilder().setLenient().create())) .client(client) .build() .create((AccuWeatherApi.class)); }
public CaiYunWeatherService() { OkHttpClient client = getClientBuilder() .addInterceptor(new GzipInterceptor()) // .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)) .build(); client.dispatcher().setMaxRequestsPerHost(1); this.api = new Retrofit.Builder() .baseUrl(BuildConfig.CAIYUN_WEATHER_BASE_URL) .addConverterFactory( GsonConverterFactory.create( new GsonBuilder().setLenient().create())) .client(client) .build() .create((CaiYunApi.class)); }
/** Deserialize from json. */ public static <T> T fromJson(String s, Class<T> c) throws IOException { FileUtils.LOG.debug("Deserializing from json to " + c); T retval; // For some reason, this only works for auto-generated Google API // classes if (c.toString().startsWith("com.google.api.services.")) { FileUtils.LOG.debug("Using Google APIs JsonParser"); retval = Utils.getDefaultJsonFactory().createJsonParser(s).parse(c); } else { FileUtils.LOG.debug("Using Gson"); retval = new GsonBuilder().setLenient().create().fromJson(s, c); } return retval; }
/** * 第一种方式 * @return Gson对象 */ public static Gson getJson() { if (gson == null) { GsonBuilder builder = new GsonBuilder(); builder.setLenient(); builder.setFieldNamingStrategy(new AnnotateNaming()); builder.serializeNulls(); gson = builder.create(); } return gson; }
public static GsonBuilder createGerritGsonBuilder( boolean nonExecutable, PlatformAbstractionLayer abstractionLayer) { GsonBuilder builder = new GsonBuilder() .setVersion(GerritApi.API_VERSION) .registerTypeAdapter(Date.class, new GerritUtcDateAdapter()) .registerTypeAdapter(ServerVersion.class, new GerritServerVersionAdapter()) .registerTypeAdapter(ApprovalInfo.class, new GerritApprovalInfoAdapter()) .registerTypeAdapter(Base64Data.class, new GerritBas64Adapter(abstractionLayer)) .setLenient(); if (nonExecutable) { builder.generateNonExecutableJson(); } return builder; } }
public ClientSidePerformanceComparatorResultData parse(String json) throws ProcessingException { Type type = new TypeToken<ClientSidePerformanceReport>() { }.getType(); try { ClientSidePerformanceReport report = new GsonBuilder().setLenient().create() .fromJson(json, type); ComparatorStepResult.Status result = getResultStatus(report.getPrettyOverallScore()); return new ClientSidePerformanceComparatorResultData(result, report); } catch (JsonSyntaxException e) { throw new ProcessingException(e.getMessage(), e); } }
public ClientSidePerformanceComparatorResultData parse(String json) throws ProcessingException { Type type = new TypeToken<ClientSidePerformanceReport>() { }.getType(); try { ClientSidePerformanceReport report = new GsonBuilder().setLenient().create() .fromJson(json, type); ComparatorStepResult.Status result = getResultStatus(report.getPrettyOverallScore()); return new ClientSidePerformanceComparatorResultData(result, report); } catch (JsonSyntaxException e) { throw new ProcessingException(e.getMessage(), e); } }