All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.javasimon.console.json.JsonStringifierFactory Maven / Gradle / Ivy

There is a newer version: 4.2.0
Show newest version
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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy