package cn.ey.biz.module.external.api.hr.feign.config;

import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;

import feign.FeignException;
import feign.Response;
import feign.codec.DecodeException;
import feign.codec.Decoder;

/**
 * 财务中台feign接口解码器
 * @author 86182
 *
 */
public class HrResponseDecoder implements Decoder {
	
	private final Logger log = LoggerFactory.getLogger(getClass());
	
	 private static final Charset UTF_8 = StandardCharsets.UTF_8;

	@Override
	public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException {
		Reader asReader = response.body().asReader(UTF_8);
		String bodyStr = IOUtils.toString(asReader);
		log.info("HR调用结果==>"+JSON.toJSONString(bodyStr));
		Object parseObject = JSON.parseObject(bodyStr,type);
		return parseObject;
		
	}	
}
