Skip to content

DSD metadataAttributeUsages dropped (and JsonParseException logged) on JSON 2.0 -> XML 2.1 structure conversion #88

Description

@iliia-veselov

StatGPT SDMX Proxy version

0.1.0

What steps will reproduce the bug?

  1. Configure an SDMX 3.0 registry that serves SDMX-JSON 2.0 and declares metadataAttributeUsages on its DSDs (e.g. IMF: IMF.STA:DSD_QNEA(7.0.0) has 25 - DOI, FULL_DESCRIPTION, AUTHOR, ...), with the PRESERVE_METADATA_ATTRIBUTE_USAGES structure fixture enabled.
  2. Request that DSD from the proxy asking for SDMX-ML 2.1:
    GET /statgpt/sdmx-proxy/api/v0/sdmx/3.0/structure/dataflow/IMF.STA/QNEA/7.0.0?references=datastructure
    Accept: application/vnd.sdmx.structure+xml;version=2.1
    
  3. The proxy fetches JSON 2.0 from the registry and converts it to XML 2.1.
  4. Inspect the response and the proxy logs.

What is the expected behavior?

The metadataAttributeUsages should survive into the 2.1 output. SDMX-ML 2.1 has no MetadataAttributeUsage element, but the registry's own canonical 2.1 form folds each usage into the DSD AttributeList as a regular DataAttribute (IMF's /sdmx/2.1/datastructure/... returns 18 real + 25 folded = 43 <str:Attribute>, each with a <str:ConceptIdentity> derived from the MSD). The proxy's 2.1 output should match that - and produce no errors.

What do you see instead?

Two problems:

  1. Data loss: the converted 2.1 XML contains only the 18 real DSD attributes; all 25 metadata-attribute usages are dropped (0 MetadataAttributeUsage, 0 folded attributes).
  2. Noisy error per DSD: the JSON-only MetadataAttributeUsagePreserver runs even when the output is XML and tries to parse the XML as JSON, throwing (swallowed, logged at WARN) once per DSD:
    WARN  c.e.s.s.f.s.MetadataAttributeUsagePreserver: Failed to re-inject metadataAttributeUsages into converted JSON; returning unchanged output
    com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value ...
        at com.epam.sdmxproxy.services.fixture.structure.MetadataAttributeUsagePreserver.inject(MetadataAttributeUsagePreserver.java:92)
        at com.epam.sdmxproxy.services.adapter.AdapterRouterImpl.lambda$getStructuresConversion$0(AdapterRouterImpl.java:198)
    
    Observed 17 occurrences in one capture window; 0 successful restores across 92 XML conversions.

Root cause: AdapterRouterImpl.getStructuresConversion runs the preserver whenever the marker is configured, without checking the output format. The preserver is JSON-output-only (inject() calls objectMapper.readTree(convertedJson)), so on XML output it always throws; and there is no mechanism that carries the usages into XML 2.1 at all.

Additional information

  • Diagnosis and evidence: docs/discussions/metadata-attribute-usages-2.1-xml.md. Design: docs/designs/032-structure-xml-21-metadata-attribute-usages/DESIGN.md. Fixed in PR fix: DSD metadataAttributeUsages dropped (and JsonParseException logged) on JSON 2.0 -> XML 2.1 structure conversion #87.
  • MetadataAttributeUsage exists only in the SDMX 3.0 schema (sdmx-core-2.3.9/.../xsd/3_0/SDMXStructureDataStructure.xsd), absent from any 2.1 schema - hence the fold-to-DataAttribute representation.
  • JSON output is unaffected (the preserver works there); the defect is specific to the JSON 2.0 -> XML 2.1 structure path with the fixture enabled.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions