All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nytimes.android.external.store3.middleware.GsonStringParser Maven / Gradle / Ivy

There is a newer version: 3.1.1
Show newest version
package com.nytimes.android.external.store3.middleware;

import com.google.gson.Gson;
import com.nytimes.android.external.store3.base.Parser;
import com.nytimes.android.external.store3.util.ParserException;

import java.lang.reflect.Type;

import javax.inject.Inject;

import io.reactivex.annotations.NonNull;

import static com.nytimes.android.external.cache3.Preconditions.checkNotNull;

public class GsonStringParser implements Parser {

    private final Gson gson;
    private final Type type;

    @Inject
    public GsonStringParser(Gson gson, Type parsedClass) {
        checkNotNull(gson, "Gson can't be null");
        checkNotNull(parsedClass, "Type can't be null");
        this.gson = gson;
        this.type = parsedClass;
    }

    @Override
    public Parsed apply(@NonNull String s) throws ParserException {
        return gson.fromJson(s, type);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy