Skip to content

Commit 1d37d8c

Browse files
Merge branch 'ml-inference-unified-api-elastic' of github.com:elastic/elasticsearch into ml-inference-unified-api-elastic
2 parents a530f02 + 0fb9a17 commit 1d37d8c

File tree

7 files changed

+624
-253
lines changed

7 files changed

+624
-253
lines changed

server/src/main/java/org/elasticsearch/common/xcontent/ChunkedToXContentHelper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.common.collect.Iterators;
1313
import org.elasticsearch.xcontent.ToXContent;
1414

15+
import java.util.Collections;
1516
import java.util.Iterator;
1617

1718
public enum ChunkedToXContentHelper {
@@ -53,6 +54,14 @@ public static Iterator<ToXContent> field(String name, String value) {
5354
return Iterators.single(((builder, params) -> builder.field(name, value)));
5455
}
5556

57+
public static Iterator<ToXContent> optionalField(String name, String value) {
58+
if (value == null) {
59+
return Collections.emptyIterator();
60+
} else {
61+
return field(name, value);
62+
}
63+
}
64+
5665
/**
5766
* Creates an Iterator of a single ToXContent object that serializes the given object as a single chunk. Just wraps {@link
5867
* Iterators#single}, but still useful because it avoids any type ambiguity.

0 commit comments

Comments
 (0)