Avoid using the BeanToJsonConverter within Json
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
+import java.io.StringWriter;
import java.io.UncheckedIOException;
+import java.io.Writer;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
private final BeanToJsonConverter toJson = new BeanToJsonConverter();
public String toJson(Object toConvert) {
- return toJson.convert(toConvert);
+ try (Writer writer = new StringWriter();
+ JsonOutput jsonOutput = newOutput(writer)) {
+ jsonOutput.write(toConvert);
+ return writer.toString();
+ } catch (IOException e) {
+ throw new JsonException(e);
+ }
}
public <T> T toType(String source, Type typeOfT) {
