Search in sources :

Example 1 with JsonWriter

use of net.morimekta.util.json.JsonWriter in project providence by morimekta.

the class JsonSerializer method serialize.

@Override
public <T extends PMessage<T, F>, F extends PField> int serialize(@Nonnull OutputStream output, @Nonnull T message) throws IOException {
    CountingOutputStream counter = new CountingOutputStream(output);
    JsonWriter jsonWriter = prettyPrint ? new PrettyJsonWriter(counter) : new JsonWriter(counter);
    appendMessage(jsonWriter, message);
    jsonWriter.flush();
    counter.flush();
    return counter.getByteCount();
}
Also used : CountingOutputStream(net.morimekta.util.io.CountingOutputStream) PrettyJsonWriter(net.morimekta.util.json.PrettyJsonWriter) PrettyJsonWriter(net.morimekta.util.json.PrettyJsonWriter) JsonWriter(net.morimekta.util.json.JsonWriter)

Example 2 with JsonWriter

use of net.morimekta.util.json.JsonWriter in project providence by morimekta.

the class JsonSerializer method serialize.

@Override
public <T extends PMessage<T, F>, F extends PField> int serialize(@Nonnull OutputStream output, @Nonnull PServiceCall<T, F> call) throws IOException {
    CountingOutputStream counter = new CountingOutputStream(output);
    JsonWriter jsonWriter = prettyPrint ? new PrettyJsonWriter(counter) : new JsonWriter(counter);
    jsonWriter.array().value(call.getMethod());
    if (enumValueType == IdType.ID) {
        jsonWriter.value(call.getType().asInteger());
    } else {
        jsonWriter.valueUnescaped(call.getType().asString().toLowerCase(Locale.US));
    }
    jsonWriter.value(call.getSequence());
    appendMessage(jsonWriter, call.getMessage());
    jsonWriter.endArray().flush();
    counter.flush();
    return counter.getByteCount();
}
Also used : CountingOutputStream(net.morimekta.util.io.CountingOutputStream) PrettyJsonWriter(net.morimekta.util.json.PrettyJsonWriter) PrettyJsonWriter(net.morimekta.util.json.PrettyJsonWriter) JsonWriter(net.morimekta.util.json.JsonWriter)

Example 3 with JsonWriter

use of net.morimekta.util.json.JsonWriter in project providence by morimekta.

the class JsonSerializer method serialize.

public <T extends PMessage<T, F>, F extends PField> void serialize(@Nonnull PrintWriter output, @Nonnull T message) throws IOException {
    JsonWriter jsonWriter = prettyPrint ? new PrettyJsonWriter(new IndentedPrintWriter(output)) : new JsonWriter(output);
    appendMessage(jsonWriter, message);
    jsonWriter.flush();
}
Also used : PrettyJsonWriter(net.morimekta.util.json.PrettyJsonWriter) PrettyJsonWriter(net.morimekta.util.json.PrettyJsonWriter) JsonWriter(net.morimekta.util.json.JsonWriter) IndentedPrintWriter(net.morimekta.util.io.IndentedPrintWriter)

Aggregations

JsonWriter (net.morimekta.util.json.JsonWriter)3 PrettyJsonWriter (net.morimekta.util.json.PrettyJsonWriter)3 CountingOutputStream (net.morimekta.util.io.CountingOutputStream)2 IndentedPrintWriter (net.morimekta.util.io.IndentedPrintWriter)1