use of org.opensearch.common.xcontent.ConstructingObjectParser in project OpenSearch by opensearch-project.
the class ListTasksResponse method setupParser.
protected static <T> ConstructingObjectParser<T, Void> setupParser(String name, TriFunction<List<TaskInfo>, List<TaskOperationFailure>, List<OpenSearchException>, T> ctor) {
ConstructingObjectParser<T, Void> parser = new ConstructingObjectParser<>(name, true, constructingObjects -> {
int i = 0;
@SuppressWarnings("unchecked") List<TaskInfo> tasks = (List<TaskInfo>) constructingObjects[i++];
@SuppressWarnings("unchecked") List<TaskOperationFailure> tasksFailures = (List<TaskOperationFailure>) constructingObjects[i++];
@SuppressWarnings("unchecked") List<OpenSearchException> nodeFailures = (List<OpenSearchException>) constructingObjects[i];
return ctor.apply(tasks, tasksFailures, nodeFailures);
});
parser.declareObjectArray(optionalConstructorArg(), TaskInfo.PARSER, new ParseField(TASKS));
parser.declareObjectArray(optionalConstructorArg(), (p, c) -> TaskOperationFailure.fromXContent(p), new ParseField(TASK_FAILURES));
parser.declareObjectArray(optionalConstructorArg(), (p, c) -> OpenSearchException.fromXContent(p), new ParseField(NODE_FAILURES));
return parser;
}
use of org.opensearch.common.xcontent.ConstructingObjectParser in project OpenSearch by opensearch-project.
the class AcknowledgedResponse method generateParser.
protected static <T> ConstructingObjectParser<T, Void> generateParser(String name, Function<Boolean, T> ctor, String parseField) {
ConstructingObjectParser<T, Void> p = new ConstructingObjectParser<>(name, true, args -> ctor.apply((boolean) args[0]));
p.declareBoolean(constructorArg(), new ParseField(parseField));
return p;
}
use of org.opensearch.common.xcontent.ConstructingObjectParser in project OpenSearch by opensearch-project.
the class ShardsAcknowledgedResponse method buildParser.
private static ConstructingObjectParser<ShardsAcknowledgedResponse, Void> buildParser() {
ConstructingObjectParser<ShardsAcknowledgedResponse, Void> p = new ConstructingObjectParser<>("freeze", true, args -> new ShardsAcknowledgedResponse((boolean) args[0], (boolean) args[1]));
p.declareBoolean(constructorArg(), new ParseField(AcknowledgedResponse.PARSE_FIELD_NAME));
p.declareBoolean(constructorArg(), new ParseField(SHARDS_PARSE_FIELD_NAME));
return p;
}
Aggregations