Skip to content

Support custom mapping files in X12Reader#81

Open
AbhinavMir wants to merge 1 commit into
imsweb:masterfrom
AbhinavMir:feature-custom-mapping-files
Open

Support custom mapping files in X12Reader#81
AbhinavMir wants to merge 1 commit into
imsweb:masterfrom
AbhinavMir:feature-custom-mapping-files

Conversation

@AbhinavMir

Copy link
Copy Markdown

Adds the ability to parse X12 files against a user-supplied mapping definition, rather than being limited to the standards enumerated in X12Reader.FileType.

What changed

  • New X12Mapping interface exposing the transaction definition and the expected ANSI version (the GS08 value). It includes a shared, secured XStream loader so built-in and custom mappings parse identically.
  • FileType now implements X12Mapping.
  • New CustomX12Mapping builds an X12Mapping from a user-supplied mapping XML stream plus a version string.
  • X12Reader gains constructors accepting any X12Mapping (File / InputStream / Reader, with optional Charset). The existing FileType constructors delegate to them, so the public API is fully backward compatible.

Usage

try (InputStream mappingStream = new FileInputStream("/path/271.5010.X279.A1.xml")) {
    X12Mapping mapping = new CustomX12Mapping("005010X279A1", mappingStream);
    X12Reader reader = new X12Reader(mapping, new File("/path/file.txt"));
}

Tests

  • testCustomMapping parses a 270 file through a custom mapping and asserts the result matches parsing the same file via the built-in FileType.
  • testCustomMappingVersionMismatch verifies a wrong version is rejected.

README updated with a "Custom mapping files" section. All existing tests, checkstyle, and spotbugs pass.

X12Reader was limited to the standards enumerated in FileType. Add an
X12Mapping interface (transaction definition + expected ANSI version) so
callers can parse files against a mapping that is not built in.

- FileType now implements X12Mapping.
- CustomX12Mapping builds an X12Mapping from a user-supplied mapping XML
  stream and version string, reusing the same secured XStream loader.
- X12Reader gains constructors accepting any X12Mapping (File, InputStream,
  Reader, with optional Charset); the existing FileType constructors
  delegate to them, so the public API is unchanged.

Adds tests parsing a file through a custom mapping and verifying the result
matches the built-in FileType, plus a version-mismatch rejection test. README
documents the new usage.
@ctmay4 ctmay4 requested a review from angelaszek June 17, 2026 12:09
@ctmay4

ctmay4 commented Jun 17, 2026

Copy link
Copy Markdown
Member

@angelaszek can you please take a look?

@ctmay4

ctmay4 commented Jun 17, 2026

Copy link
Copy Markdown
Member

Please fix merge conflicts.

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.

2 participants