/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.crunii.com</a>
 */
package com.crunii.micro.common.config;

import com.crunii.micro.common.jackson.ObjectMapperFactoryBean;
import com.crunii.micro.common.spring.SpringUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 田平 create 2019年12月23日下午3:48:10
 */
@Configuration
public class CommConfiguration {

	@Value("${jackson.xss.serializer:false}")
	private boolean enableXssSerializer;

	@Value("${jackson.xss.deserializer:true}")
	private boolean enableXssDeserializer;

	@Bean(name = "objectMapper")
	public ObjectMapper regObjectMapper() throws Exception {
		ObjectMapperFactoryBean bean = new ObjectMapperFactoryBean(enableXssSerializer, enableXssDeserializer);
		SimpleModule simpleModule = new SimpleModule();
		simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
		simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
		ObjectMapper objectMapper = bean.getObject().registerModule(simpleModule);
		return objectMapper;
	}

	@Bean(name = "springUtil")
	public SpringUtil regSpringUtil() {
		return new SpringUtil();
	}

}
