2 * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.api;
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import java.io.IOException;
13 import java.io.OutputStream;
14 import org.eclipse.jdt.annotation.NonNullByDefault;
15 import org.opendaylight.restconf.api.query.PrettyPrintParam;
16 import org.opendaylight.yangtools.concepts.Immutable;
19 * A body which is capable of being formatted to an {@link OutputStream} in either JSON or XML format using particular
20 * {@link PrettyPrintParam}.
23 public abstract class FormattableBody implements Immutable {
25 * Write the content of this body as a JSON document.
27 * @param prettyPrint a {@link PrettyPrintParam}
28 * @param out output stream
29 * @throws IOException if an IO error occurs.
31 public abstract void formatToJSON(PrettyPrintParam prettyPrint, OutputStream out) throws IOException;
34 * Write the content of this body as an XML document.
36 * @param prettyPrint a {@link PrettyPrintParam}
37 * @param out output stream
38 * @throws IOException if an IO error occurs.
40 public abstract void formatToXML(PrettyPrintParam prettyPrint, OutputStream out) throws IOException;
42 protected abstract ToStringHelper addToStringAttributes(ToStringHelper helper);
45 public final String toString() {
46 return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();