package com.goafanti.core.cache.serializer;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

public class FastJsonRedisSerializer implements RedisSerializer<Object> {
	public FastJsonRedisSerializer() {
		ParserConfig pc = ParserConfig.getGlobalInstance();
		pc.addAccept("com.goafanti.common.model.IndustryCategory");
		pc.addAccept("com.goafanti.common.model.DistrictGlossory");
		pc.addAccept("com.goafanti.common.model.HtmlFragment");
		pc.addAccept("com.goafanti.common.model.News");
		pc.addAccept("com.goafanti.news.bo.NewsSummary");
		pc.addAccept("com.goafanti.common.model.Banners");
		pc.addAccept("com.goafanti.common.model.EngagedFieldGlossory");
		pc.addAccept("com.goafanti.star.bo.BigShotStarListBo");
		pc.addAccept("com.goafanti.lecture.bo.LectureListBo");
		pc.addAccept("com.goafanti.lecture.bo.BigShotLectureListBo");
		pc.addAccept("com.goafanti.news.bo.NewsPortalList");
		pc.addAccept("com.goafanti.common.model.Activity");
		pc.addAccept("com.goafanti.order.bo.OutStatisticsList");
		pc.addAccept("com.goafanti.order.bo.OutProvinceStatisticsList");
		pc.addAccept("com.goafanti.weChat.bo.OutPublicStatistics");
		pc.addAccept("com.goafanti.core.mybatis.page.Pagination");
		pc.addAccept("com.goafanti.common.bo.Result");
		pc.addAccept("com.goafanti.permission.bo.PermissionBo");
		pc.addAccept("com.goafanti.expenseAccount.bo.OutExpenseAccountStatistics");
		pc.addAccept("java.util.Map");
		pc.addAccept("com.goafanti.common.bo.OutPoverty");
		pc.addAccept("com.goafanti.common.bo.OutPovertyFlag");
		pc.addAccept("com.goafanti.expenseAccount.bo.ExpenseCountsBo");
		pc.addAccept("com.goafanti.weChat.bo.releaseAndExpenseCountOut");
		pc.addAccept("com.goafanti.admin.bo.SalesTeamBo");

	}

	@Override
	public byte[] serialize(Object t) throws SerializationException {
		if (t == null)
			return null;
		return JSON.toJSONBytes(t, SerializerFeature.WRITE_MAP_NULL_FEATURES, SerializerFeature.QuoteFieldNames,
				SerializerFeature.WriteClassName, SerializerFeature.IgnoreNonFieldGetter);
	}

	@Override
	public Object deserialize(byte[] bytes) throws SerializationException {
		if (bytes == null)
			return null;
		return JSON.parse(bytes);
	}

}
