Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert JSON to AnalyzeResult #48175

Open
ashp-grouptree opened this issue Feb 7, 2025 · 4 comments
Open

Convert JSON to AnalyzeResult #48175

ashp-grouptree opened this issue Feb 7, 2025 · 4 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Cognitive - Form Recognizer customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed Workflow: The Azure SDK team believes it to be addressed and ready to close. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@ashp-grouptree
Copy link

ashp-grouptree commented Feb 7, 2025

Azure.AI.FormRecognizer 4.1.0

Query/Question

Will there ever be more support to mock an AnalyzeResult object from a JSON response obtained from the Document Intelligence Studio? I can use DocumentAnalysisModelFactory.AnalyzeResult to create a mock object but there is no support for populating DocumentTable etc.? For testing purposes we should have support for creating an exact replica of the endpoint response surely?

Environment

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.101\

.NET SDK:
Version: 9.0.101
Commit: eedb237549
Workload version: 9.0.100-manifests.4a280210
MSBuild version: 17.12.12+1cce77968

Visual Studio Version 17.12.3

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Feb 7, 2025
@jsquire jsquire added Client This issue points to a problem in the data-plane of the library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Cognitive - Form Recognizer and removed needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Feb 7, 2025
@jsquire
Copy link
Member

jsquire commented Feb 7, 2025

Thank you for your feedback. Tagging and routing to the team member best able to assist.

@kinelski
Copy link
Member

Hello @ashp-grouptree,

You can also mock DocumentTable and other models using the DocumentAnalysisModelFactory. For example, you could do:

List<DocumentTable> tables = new() {
    DocumentAnalysisModelFactory.DocumentTable(rowCount: 3, columnCount: 1);
    DocumentAnalysisModelFactory.DocumentTable(rowCount: 5, columnCount: 2);
};
AnalyzeResult result = DocumentAnalysisModelFactory.AnalyzeResult(tables: tables);

You should be able to replicate any possible result returned by the service if you use the model factory to create your models.

That said, please be aware that Azure.AI.FormRecognizer is an old package that won't receive more feature updates in the future. Going forward, Azure.AI.DocumentIntelligence is the official package to go for the Document Intelligence service.

The new package supports JSON serialization/deserialization of our models, which might make the process of mocking AnalyzeResult easier depending on your scenario:

JsonSerializerOptions options = new JsonSerializerOptions()
{
    Converters = { new JsonModelConverter() }
};

// Serializing AnalyzeResult into JSON.
AnalyzeResult model = DocumentIntelligenceModelFactory.AnalyzeResult();
string data = JsonSerializer.Serialize(model, options);

// Deserializing AnalyzeResult from JSON.
AnalyzeResult? model = JsonSerializer.Deserialize<AnalyzeResult>(data, options);

If you ever decide to migrate, consider taking a look at our README and our migration guide for a complete list of missing features.

@kinelski kinelski added issue-addressed Workflow: The Azure SDK team believes it to be addressed and ready to close. and removed needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Feb 11, 2025
Copy link

Hi @ashp-grouptree. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

@ashp-grouptree
Copy link
Author

Thanks for the help. This looks to be what we need will give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. Cognitive - Form Recognizer customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed Workflow: The Azure SDK team believes it to be addressed and ready to close. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

3 participants