/**
 * 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.jackson;

import java.io.IOException;

import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.util.StringUtils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
 * @author 田平 create 2019年5月27日上午9:29:27
 */
public class XssStringSerializer extends JsonSerializer<String> {

	@Override
	public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
		if (StringUtils.hasText(value)) {
			gen.writeString(StringEscapeUtils.escapeHtml4(value));
		} else {
			gen.writeNull();
		}
	}

}
