What is the correct way to convert SearchHit.getSortValues/SortValues object to String

Following code returns garbage for some values:

for (SearchHit result : output) {
for (Object value : result.getSortValues()) { // result.getSortValues() returns object array
System.out.println(value.toString());
}
}

Has anyone used getSortValues()/ SortValues() Java APIs before ? Return type of this API is an object array and converting these objects to string doesn't always work.

Take this use case for example - If you have applied "filtered" sorting in your query and someone of the results don't satisfy the filter criteria, the value of sroted values should be null. Instead of null, getSortValues()/ SortValues() API is returning some junk value.

Also, if I check the "type" of object returned by this API, it is of type - org.elasticsearch.common.text.StringAndBytesText.

My question is, why this API returns object array and not String array ?