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.yangtools.concepts.Immutable;
18 * A body which is capable of being formatted to an {@link OutputStream} in either JSON or XML format using particular
19 * {@link FormatParameters}.
22 public abstract class FormattableBody implements Immutable {
24 * Write the content of this body as a JSON document.
26 * @param format {@link FormatParameters}
27 * @param out output stream
28 * @throws IOException if an IO error occurs.
30 public abstract void formatToJSON(FormatParameters format, OutputStream out) throws IOException;
33 * Write the content of this body as an XML document.
35 * @param format {@link FormatParameters}
36 * @param out output stream
37 * @throws IOException if an IO error occurs.
39 public abstract void formatToXML(FormatParameters format, OutputStream out) throws IOException;
41 protected abstract ToStringHelper addToStringAttributes(ToStringHelper helper);
44 public final String toString() {
45 return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();