Example usage for com.google.gson.internal.bind TypeAdapters newFactory

List of usage examples for com.google.gson.internal.bind TypeAdapters newFactory

Introduction

In this page you can find the example usage for com.google.gson.internal.bind TypeAdapters newFactory.

Prototype

public static <TT> TypeAdapterFactory newFactory(final Class<TT> type, final TypeAdapter<TT> typeAdapter) 

Source Link

Usage

From source file:com.google.caliper.json.GsonModule.java

License:Apache License

@Provides
@ForInstant
TypeAdapterFactory provideTypeAdapterFactoryForInstant(InstantTypeAdapter typeAdapter) {
    return TypeAdapters.newFactory(Instant.class, typeAdapter);
}

From source file:dk.ilios.spanner.Spanner.java

License:Apache License

public void start() {
    try {//ww  w.  j a v a  2  s. c om
        callback.onStart();
        benchmarkConfig = benchmarkClass.getConfiguration();
        File baseline = benchmarkConfig.getBaseLineFile();

        ImmutableSet<Instrument> instruments = getInstruments(benchmarkConfig);

        int poolSize = benchmarkConfig.getNoBenchmarkThreads();
        ListeningExecutorService executor = MoreExecutors
                .listeningDecorator(Executors.newFixedThreadPool(poolSize));

        StdOut stdOut = new AndroidStdOut();
        Run runInfo = new Run.Builder(UUID.randomUUID()).label("Spanner benchmark test")
                .startTime(Instant.now()).configuration(benchmarkConfig).build();

        ExperimentSelector experimentSelector = new AndroidExperimentSelector(benchmarkClass, instruments);

        // GSON config
        GsonBuilder gsonBuilder = new GsonBuilder().setExclusionStrategies(new AnnotationExclusionStrategy());
        gsonBuilder
                .registerTypeAdapterFactory(TypeAdapters.newFactory(Instant.class, new InstantTypeAdapter()));
        Gson gson = gsonBuilder.create();

        // Configure baseline data
        Trial[] baselineData;
        if (baseline != null) {
            BufferedReader br = null;
            try {
                br = new BufferedReader(new FileReader(baseline));
                baselineData = gson.fromJson(br, Trial[].class);
                br.close();
            } catch (java.io.IOException e) {
                throw new RuntimeException(e);
            } finally {
                if (br != null) {
                    try {
                        br.close();
                    } catch (IOException ignored) {
                    }
                }
            }
        } else {
            baselineData = new Trial[0];
        }

        // Configure ResultProcessors
        Set<ResultProcessor> processors = new HashSet<>();
        if (benchmarkConfig.getResultsFile() != null) {
            OutputFileDumper dumper = new OutputFileDumper(gson, benchmarkConfig.getResultsFile());
            processors.add(dumper);
        }
        if (benchmarkConfig.isUploadResults()) {
            HttpUploader uploader = new HttpUploader(stdOut, gson, benchmarkConfig);
            processors.add(uploader);
        }
        processors.addAll(benchmarkConfig.getResultProcessors());
        ImmutableSet<ResultProcessor> resultProcessors = ImmutableSet.copyOf(processors);

        // Configure runner
        SpannerRun run = new ExperimentingSpannerRun(benchmarkConfig, stdOut, runInfo, resultProcessors,
                experimentSelector, executor, baselineData, callback);

        // Run benchmark
        run.run();
        callback.onComplete();
    } catch (Exception e) {
        // Report all exceptions
        callback.onError(e);
    }
}

From source file:org.lastaflute.core.json.adapter.NumberGsonAdaptable.java

License:Apache License

default TypeAdapterFactory createBigDecimalTypeAdapterFactory() {
    return TypeAdapters.newFactory(BigDecimal.class, createTypeAdapterBigDecimal());
}

From source file:org.lastaflute.core.json.adapter.StringGsonAdaptable.java

License:Apache License

default TypeAdapterFactory createStringTypeAdapterFactory() {
    return TypeAdapters.newFactory(String.class, createTypeAdapterString());
}