Skip to content

Fix docling example metadata extraction writing invalid JSON - #196

Open
Croway wants to merge 1 commit into
apache:mainfrom
Croway:fix-docling-metadata-extraction-json
Open

Fix docling example metadata extraction writing invalid JSON#196
Croway wants to merge 1 commit into
apache:mainfrom
Croway:fix-docling-metadata-extraction-json

Conversation

@Croway

@Croway Croway commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

The document-metadata-extractor route used docling:EXTRACT_STRUCTURED_DATA as the endpoint, but camel-docling only dispatches on the operation query parameter (or the CamelDoclingOperation header) - the URI path segment is descriptive only. Without an explicit operation=... parameter, the endpoint silently fell back to its CONVERT_TO_MARKDOWN default, so the "metadata" route was actually just converting to markdown and writing it into a .json file (invalid JSON).

  • Both routes now pass an explicit operation=CONVERT_TO_MARKDOWN / operation=EXTRACT_STRUCTURED_DATA query parameter. The URI path segment itself was renamed to a lowercase, hyphenated label (docling:convert-to-markdown, docling:extract-structured-data) instead of repeating the operation name, to make clear it's just an endpoint id and the operation parameter is what actually selects the behavior.
  • EXTRACT_STRUCTURED_DATA returns a DoclingDocument object, not JSON text (the outputFormat parameter isn't read by that operation, and there's no type converter for the object), so the route now marshals it to JSON via camel-jackson before writing it to file.

I've also filed the root cause against camel-docling itself: apache/camel#26102 (the docling:<operationId> URI path segment not being honored). This PR fixes the example regardless of when/whether that lands, since the explicit operation=... parameter and the JSON marshalling step are both needed either way.

Test plan

  • Reproduced against a live docling-serve container (docker run -p 5001:5001 ghcr.io/docling-project/docling-serve:latest)
  • Before: output/metadata/*.json contained markdown text, invalid JSON
  • After: output/metadata/*.json contains valid, well-formed JSON (DoclingDocument schema)
  • Verified the primary document-to-markdown-converter route still produces correct markdown output
  • mvn clean package succeeds

🤖 Generated with Claude Code

https://claude.ai/code/session_01Hs6c6LpuL8ZZ3gaSXwt7CS

The document-metadata-extractor route used docling:EXTRACT_STRUCTURED_DATA
as the endpoint URI path, but camel-docling only dispatches on the
"operation" query parameter (or the CamelDoclingOperation header) - the
URI path segment is descriptive only. Without it, the endpoint silently
fell back to its CONVERT_TO_MARKDOWN default, so the "metadata" route was
actually just converting to markdown and writing it into a .json file.

Also add the missing operation query parameter, and marshal the
DoclingDocument result to JSON explicitly (EXTRACT_STRUCTURED_DATA returns
a structured object, not JSON text, and camel-docling has no built-in
type converter for it), via camel-jackson.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hs6c6LpuL8ZZ3gaSXwt7CS
@Croway
Croway force-pushed the fix-docling-metadata-extraction-json branch from 9bc5b04 to 211aba7 Compare September 3, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant