Bug in Document Intelligence SDK - LinkedHashMap cannot be cast to class DocumentField
Ben Graff
0
Reputation points
Exception:
java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class com.azure.ai.formrecognizer.documentanalysis.models.DocumentField (java.util.LinkedHashMap is in module java.base of loader 'bootstrap';
import com.azure.ai.formrecognizer.documentanalysis.models.AnalyzeResult;import com.azure.ai.formrecognizer.documentanalysis.models.AnalyzedDocument;import com.azure.ai.formrecognizer.documentanalysis.models.DocumentField;import com.azure.ai.formrecognizer.documentanalysis.models.DocumentFieldType;
// Get results back
AnalyzeResult results= analyzeDocumentPoller.getFinalResult().getDocuments().get(0);
Map<String, DocumentField> taxFields = results.getFields();
DocumentField employerField = taxFields.get("Employer");
// PROBLEM LINES
Map<String, DocumentField> employerDataFieldMap = employerField.getValueAsMap();
// Error thrown here from this line not returning a DocumentField like it should
DocumentField employerNameObj = employerDataFieldMap.get("Name");
getValueAsMap() returns a map of DocoumentField objects so I can't have it return a map to fit the type that it's receiving from .get("Name")
azure1.png
This is a work around but it would be nice if this could be fixed. Not sure how to get this to the attention of any developers.
Map<String, Object> employerDataFieldMap = (Map<String, Object>)employerField.getValue();
Object employerNameMap = employerDataFieldMap.get("Name");
Map<String, Object> nameMap = (Map<String, Object>) employerNameMap;
String name = (String) nameMap.get("value");
Sign in to answer