org.javasimon.console.json.JsonStringifierFactory Maven / Gradle / Ivy
package org.javasimon.console.json;
import org.javasimon.console.text.BaseStringifier;
import org.javasimon.console.text.Stringifier;
import org.javasimon.console.text.StringifierFactory;
/**
* Value formatter for JSON responses.
*
* @author gquintana
*/
public class JsonStringifierFactory extends StringifierFactory {
@Override
protected Stringifier registerNullStringifier() {
return registerNullStringifier("\"\"");
}
@Override
protected Stringifier registerStringStringifier(Stringifier nullStringifier) {
Stringifier stringStringifier = new BaseStringifier(nullStringifier) {
@Override
protected String doToString(String s) {
return "\"" + s.replace("\\", "\\\\").replace("\"", "\\\"").replace("/", "\\/") + "\"";
}
};
compositeStringifier.add(String.class, stringStringifier);
return stringStringifier;
}
}