「Java」CharacterEscapesクラスでJacksonのエスケープ対象文字を制御するサンプル

1.親クラスの定義

public  class SampleBase {

  private ObjectMapper mapper = new ObjectMapper();

 public SampleBase(){
   mapper.setconfigure(Feature.ESCAPE_NONE_ASCII,TRUE);
   mapper.getFactory().setCharacterEscapes(mew JsonChildEscape());
 }
 
}

2.子クラスの定義

public class JsonChildEscape extends CharacterEscapes{

  private int[] codeEscapes;
  
  public JsonChildEscape() {
    codeEscapes = standardcodeEscapesForJSON();
    codeEscapes['<'] = '<';
    codeEscapes['>'] = '>';
    codeEscapes['/'] = '/';
  }
  	@Override
      public int[] getEscapeCodesForAscii() {
            return codeEscapes == null ? null : codeEscapes.clone();
      }

      @Override
      public SerializableString getEscapeSequence(int ch) {
            return null;
      }

}

 

Java

Posted by arkgame