package com.bc_chat.bc_base.JsonService;

/**
 * author：Created by zhaohaoting on 2019/2/21
 * email：526309416@qq.com
 * desc：
 */

import android.content.Context;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.facade.service.SerializationService;
import com.bc_chat.bc_base.config.RouteConfig;
import com.google.gson.Gson;

import java.lang.reflect.Type;

/**
 * 依赖注入使用，注意：必须实现SerializationService进行注册，
 */
@Route(path = RouteConfig.JSON_SERVICE)
public class JsonServiceImpl implements SerializationService {
    @Override
    public void init(Context context) {

    }

    @Override
    public <T> T json2Object(String text, Class<T> clazz) {
        return new Gson().fromJson(text, clazz);
    }

    @Override
    public String object2Json(Object instance) {
        return new Gson().toJson(instance);
    }

    @Override
    public <T> T parseObject(String input, Type clazz) {
        return new Gson().fromJson(input, clazz);
    }
}
