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

com.sigopt.model.APIResource Maven / Gradle / Ivy

There is a newer version: 6.3.0
Show newest version
package com.sigopt.model;

import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class APIResource {
    public static  T constructFromJson(String json, Class  klass) {
        T instance;
        try {
            instance = klass.newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        Type type = new TypeToken>() {}.getType();
        Map map = APIObject.fromJson(json, type);
        instance.setAll(map);
        return instance;
    }

    public static  Pagination constructPaginationFromJson(
        String json,
        Class subklass
    ) {
        Pagination p = new Pagination(subklass);
        Type type = new TypeToken>() {}.getType();
        Map map = APIObject.fromJson(json, type);
        p.setAll(map);
        return p;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy