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

io.logspace.jvm.agent.api.json.EventPageJsonSerializer Maven / Gradle / Ivy

The newest version!
/**
 * Logspace
 * Copyright (c) 2015 Indoqa Software Design und Beratung GmbH. All rights reserved.
 * This program and the accompanying materials are made available under the terms of
 * the Eclipse Public License Version 1.0, which accompanies this distribution and
 * is available at http://www.eclipse.org/legal/epl-v10.html.
 */
package io.logspace.jvm.agent.api.json;

import static io.logspace.jvm.agent.shaded.jackson.core.JsonEncoding.UTF8;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public final class EventPageJsonSerializer extends AbstractJsonSerializer {

    private EventPageJsonSerializer(OutputStream outputStream) throws IOException {
        super(outputStream);
    }

    public static String toJson(EventPage eventPage) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        toJson(eventPage, baos);

        return baos.toString(UTF8.getJavaName());
    }

    public static void toJson(EventPage eventPage, OutputStream outputStream) throws IOException {
        EventPageJsonSerializer serializer = new EventPageJsonSerializer(outputStream);
        serializer.serialize(eventPage);
        serializer.finish();
    }

    public void serialize(EventPage eventPage) throws IOException {
        this.startObject();

        this.writeMandatoryLongField("totalCount", eventPage.getTotalCount());
        this.writeMandatoryStringField("nextCursorMark", eventPage.getNextCursorMark());

        this.writeFieldName("events");
        EventJsonSerializer.toJson(eventPage.getEvents(), this.getJsonGenerator());

        this.endObject();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy