Search in sources :

Example 1 with Stringify

use of org.hjson.Stringify in project cas by apereo.

the class AbstractJacksonBackedStringSerializer method to.

@Override
@SneakyThrows
public void to(final File out, final T object) {
    try (StringWriter writer = new StringWriter()) {
        this.objectMapper.writer(this.prettyPrinter).writeValue(writer, object);
        if (isJsonFormat()) {
            try (Writer fileWriter = Files.newBufferedWriter(out.toPath(), StandardCharsets.UTF_8)) {
                final Stringify opt = this.prettyPrinter instanceof MinimalPrettyPrinter ? Stringify.PLAIN : Stringify.FORMATTED;
                JsonValue.readHjson(writer.toString()).writeTo(fileWriter, opt);
                fileWriter.flush();
            }
        } else {
            FileUtils.write(out, writer.toString(), StandardCharsets.UTF_8);
        }
    }
}
Also used : Stringify(org.hjson.Stringify) MinimalPrettyPrinter(com.fasterxml.jackson.core.util.MinimalPrettyPrinter) StringWriter(java.io.StringWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) SneakyThrows(lombok.SneakyThrows)

Example 2 with Stringify

use of org.hjson.Stringify in project cas by apereo.

the class AbstractJacksonBackedStringSerializer method to.

@Override
@SneakyThrows
public void to(final Writer out, final T object) {
    try (StringWriter writer = new StringWriter()) {
        this.objectMapper.writer(this.prettyPrinter).writeValue(writer, object);
        if (isJsonFormat()) {
            final Stringify opt = this.prettyPrinter instanceof MinimalPrettyPrinter ? Stringify.PLAIN : Stringify.FORMATTED;
            JsonValue.readHjson(writer.toString()).writeTo(out, opt);
        } else {
            IOUtils.write(writer.toString(), out);
        }
    }
}
Also used : Stringify(org.hjson.Stringify) MinimalPrettyPrinter(com.fasterxml.jackson.core.util.MinimalPrettyPrinter) StringWriter(java.io.StringWriter) SneakyThrows(lombok.SneakyThrows)

Aggregations

MinimalPrettyPrinter (com.fasterxml.jackson.core.util.MinimalPrettyPrinter)2 StringWriter (java.io.StringWriter)2 SneakyThrows (lombok.SneakyThrows)2 Stringify (org.hjson.Stringify)2 Writer (java.io.Writer)1