package com.kamco.cd.kamcoback.common.utils.html;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import org.springframework.web.util.HtmlUtils;

public class HtmlUnescapeSerializer extends JsonSerializer<String> {
  @Override
  public void serialize(
      String value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
      throws IOException {
    if (value == null) {
      jsonGenerator.writeNull();
    } else {
      jsonGenerator.writeString(HtmlUtils.htmlUnescape(value));
    }
  }
}
