Split out operation output serialization
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / server / api / OperationsPostResult.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.restconf.server.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.restconf.server.api.DatabindPath.OperationPath;
15 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
16
17 /**
18  * RESTCONF {@code /operations} content for a {@code POST} operation as per
19  * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.6">RFC8040 Operation Resource</a> and
20  * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.4.2">RFC8040 Invoke Operation Mode</a>.
21  *
22  * @param path associated {@link OperationPath}
23  * @param output Operation output, or {@code null} if output would be empty
24  */
25 public record OperationsPostResult(@NonNull OperationPath path, @Nullable ContainerNode output) {
26     public OperationsPostResult {
27         requireNonNull(path);
28         if (output != null && output.isEmpty()) {
29             output = null;
30         }
31     }
32 }