{"id":13591984,"url":"https://github.com/xlate/staedi","last_synced_at":"2026-01-12T08:54:58.687Z","repository":{"id":21907063,"uuid":"94276393","full_name":"xlate/staedi","owner":"xlate","description":"StAEDI - Streaming API for EDI: Java library featuring a reader/parser, writer/generator, and validation","archived":false,"fork":false,"pushed_at":"2024-10-29T11:06:51.000Z","size":2877,"stargazers_count":127,"open_issues_count":6,"forks_count":35,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-10-29T13:10:51.404Z","etag":null,"topics":["edi","edi-api","edi-messages","edi-reading","edi-stream","edifact","generator","parser","tradacoms","x12"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xlate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["MikeEdgar"]}},"created_at":"2017-06-14T01:48:38.000Z","updated_at":"2024-10-29T11:06:55.000Z","dependencies_parsed_at":"2024-03-26T11:39:56.261Z","dependency_job_id":"30b696d3-05ad-4145-8af2-b9a9c6c4fe71","html_url":"https://github.com/xlate/staedi","commit_stats":null,"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlate%2Fstaedi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlate%2Fstaedi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlate%2Fstaedi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlate%2Fstaedi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xlate","download_url":"https://codeload.github.com/xlate/staedi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247902093,"owners_count":21015393,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["edi","edi-api","edi-messages","edi-reading","edi-stream","edifact","generator","parser","tradacoms","x12"],"created_at":"2024-08-01T16:01:04.486Z","updated_at":"2026-01-12T08:54:58.637Z","avatar_url":"https://github.com/xlate.png","language":"Java","funding_links":["https://github.com/sponsors/MikeEdgar"],"categories":["Libraries"],"sub_categories":["Java"],"readme":"# StAEDI - Streaming API for EDI\n![Build](https://github.com/xlate/staedi/workflows/Build/badge.svg?branch=master) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=xlate_staedi\u0026metric=coverage)](https://sonarcloud.io/summary/new_code?id=xlate_staedi) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xlate_staedi\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=xlate_staedi) [![Join the chat at https://gitter.im/xlate/staedi](https://badges.gitter.im/xlate/staedi.svg)](https://gitter.im/xlate/staedi?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge) [![Maven Central](https://img.shields.io/maven-central/v/io.xlate/staedi)](https://search.maven.org/artifact/io.xlate/staedi) [![javadoc](https://javadoc.io/badge2/io.xlate/staedi/javadoc.svg)](https://javadoc.io/doc/io.xlate/staedi)\n\nStAEDI is a streaming API for EDI reading, writing, and validation in Java. [[Support](https://github.com/xlate/staedi/wiki/Support) | [Wiki](https://github.com/xlate/staedi/wiki)]\n\n![Event Flow](staedi_events.png)\n\nThe API follows the same conventions as StAX (XML API available in the standard JDK)\nusing a \"pull\" processing flow for EDI parsing and an emit flow for EDI generation.\n\n## Features\n- Support for **X12**, **EDIFACT**, and **TRADACOMS** standards\n- Read structures from an EDI stream in sequence (start loop, start segment, element data, end segment, etc.)\n- EDI Schema that allows for user-specified **validation** rules\n- Validation of **EDI standards** (segment occurrences, element type, element length constraints, etc.)\n- Validation of **industry implementations**, for example HIPAA\n- Read and write EDI data using standard Java XML interfaces (StAX)\n- Read EDI data using standard Java JSON interfaces (Jakarta JSON Processing, aka JSR-353/JSR-374)\n- Support for X12 `ISX` segment (release character, element 01 only), introduced in version `007040`\n\n## Maven Coordinates\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.xlate\u003c/groupId\u003e\n  \u003cartifactId\u003estaedi\u003c/artifactId\u003e\n  \u003cversion\u003eCURRENT VERSION\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Support\nSupport is available to assist with incorporating StAEDI into your business's application. Available services include\n- **Development of EDI validation schemas** using your documentation (e.g. PDF)\n- **Integrating StAEDI** into your Java application\n- **Troubleshooting issues** with your existing integration (not including StAEDI bugs - please open an issue)\n\nPlease email ***contact at xlate dot io*** for more information.\n\n## Have a Question?\nIf you have a question about StAEDI that may not require the opening of an issue, please head to the StAEDI Gitter channel at https://gitter.im/xlate/staedi to discuss.\n\n## Reading EDI\n\nInput data is provided using a series of events via the `EDIStreamReader` class.\nIn addition to events such as the start of a segment or element, the looping/nested structure of the\nEDI stream is represented using derived events.\n\n```\n+ Start Interchange\n| +-- Start Segment (ISA / UNB / STX)\n| |     Element Data (repeats)\n| +-- End Segment (ISA / UNB / STX)\n| |\n| +-- Start Functional Group (Optional for EDIFACT and TRADACOMS)\n| |   +-- Start Segment (GS / UNG / BAT)\n| |   |     Element Data (repeats)\n| |   +-- End Segment (GS / UNG / BAT)\n| |\n| |   +-- Start Transaction/Message\n| |   |  +-- Start Segment (ST / UNH / MHD)\n| |   |  |     Element Data (repeats)\n| |   |  +-- End Segment (ST / UNH / MHD)\n| |   |\n| |   |  // Segments / Loops specific to the transaction\n| |   |\n| |   |  +-- Start Segment (SE / UNT / MTR)\n| |   |  |     Element Data (repeats)\n| |   |  +-- End Segment (SE / UNT / MTR)\n| |   +-- End Transaction/Message\n| |\n| |   +-- Start Segment (GE / UNE / EOB)\n| |   |     Element Data (repeats)\n| |   +-- End Segment (GE / UNE / EOB)\n| +-- End Functional Group\n| |\n| +-- Start Transaction/Message (EDIFACT and TRADACOMS only, if functional group(s) not used)\n| |   // Same content as messages within group\n| +-- End Transaction/Message\n| |\n| +-- Start Segment (IEA / UNZ / END)\n| |     Element Data (repeats)\n| +-- End Segment (IEA / UNZ / END)\n+ End Interchange\n```\n\n```java\nEDIInputFactory factory = EDIInputFactory.newFactory();\n\n// Obtain Stream to the EDI document to read.\nInputStream stream = new FileInputStream(...);\n\nEDIStreamReader reader = factory.createEDIStreamReader(stream);\n\nwhile (reader.hasNext()) {\n  switch (reader.next()) {\n  case START_INTERCHANGE:\n    /* Retrieve the standard - \"X12\", \"EDIFACT\", or \"TRADACOMS\" */\n    String standard = reader.getStandard();\n\n    /*\n     * Retrieve the version string array. An array is used to support\n     * the componentized version element used in the EDIFACT standard.\n     *\n     * e.g. [ \"00501\" ] (X12) or [ \"UNOA\", \"3\" ] (EDIFACT)\n     */\n    String[] version = reader.getVersion();\n    break;\n\n  case START_SEGMENT:\n    // Retrieve the segment name - e.g. \"ISA\" (X12), \"UNB\" (EDIFACT), or \"STX\" (TRADACOMS)\n    String segmentName = reader.getText();\n    break;\n\n  case END_SEGMENT:\n    break;\n\n  case START_COMPOSITE:\n    break;\n\n  case END_COMPOSITE:\n    break;\n\n  case ELEMENT_DATA:\n    // Retrieve the value of the current element\n    String data = reader.getText();\n    break;\n  }\n}\n\nreader.close();\nstream.close();\n\n```\n\n### Disable Validation of Control Codes\n\nOut of the box, instances of `EDIStreamReader` will validate the control structures\nof X12 and EDIFACT messages (interchange, group, and transaction headers and trailers).\nThis validation includes checking that some fields contain one of an enumerated list\nof values (e.g. a known transaction set code in X12 segment `ST`, element 1).\n\nIf you wish to disable the validation of the code values but keep the validation of the\nstructure, including field sizes and types, set the `EDIInputFactory.EDI_VALIDATE_CONTROL_CODE_VALUES`\nproperty to `false` on an instance of `EDIInputFactory` prior to creating a new `EDIStreamReader`,\nas shown below.\n\n```java\n// Create an EDIInputFactory\nEDIInputFactory factory = EDIInputFactory.newFactory();\nfactory.setProperty(EDIInputFactory.EDI_VALIDATE_CONTROL_CODE_VALUES, false);\n\n// Obtain an InputStream of the EDI document to read.\nInputStream stream = new FileInputStream(...);\n\n// Create an EDIStreamReader from the stream using the factory\nEDIStreamReader reader = factory.createEDIStreamReader(stream);\n\n// Continue processing with the reader...\n```\n\n## Sample Writing X12 EDI\n\nThe below example shows how X12 data could be written. TRADACOMS and EDIFACT standards are also supported,\nusing the segments specific to those standards.\n\n```java\nEDIOutputFactory factory = EDIOutputFactory.newFactory();\n\n// Obtain Stream write the EDI document.\nOutputStream stream = new FileOutputStream(...);\n\nEDIStreamWriter writer = factory.createEDIStreamWriter(stream);\nint groupCount = 0;\n\n// Set a schema for the control structures being written (interchange, group, and transaction envelope segments)\nSchemaFactory schemaFactory = SchemaFactory.newFactory();\n/*\n * A control schema can be created with the factory by providing the standard\n * and version array. The version is an array to support multi-field versions\n * such as the composite element UNB01 for EDIFACT.\n */\nSchema controlSchema = schemaFactory.getControlSchema(EDIStreamConstants.Standards.X12, new String[] { \"00501\" });\nwriter.setControlSchema(controlSchema);\n\nwriter.startInterchange();\n\n// Write interchange header segment\nwriter.writeStartSegment(\"ISA\")\n      .writeElement(\"00\")\n      .writeElement(\"          \")\n      .writeElement(\"00\")\n      .writeElement(\"          \")\n      .writeElement(\"ZZ\")\n      .writeElement(\"ReceiverID     \")\n      .writeElement(\"ZZ\")\n      .writeElement(\"Sender         \")\n      .writeElement(\"203001\")\n      .writeElement(\"1430\")\n      .writeElement(\"^\")\n      .writeElement(\"00501\")\n      .writeElement(\"000000001\")\n      .writeElement(\"0\")\n      .writeElement(\"P\")\n      .writeElement(\":\")\n      .writeEndSegment();\n\n// Write functional group header segment\ngroupCount++;\nint txCount = 0;\nwriter.writeStartSegment(\"GS\");\nwriter.writeElement(\"FA\");\n\n// Continue writing remainder of group header and transactions, increment `txCount` for each transaction\n\nwriter.writeStartSegment(\"GE\")\n      /* Count of transactions here must match the actual count of ST/SE pairs */\n      .writeElement(String.valueOf(txCount))\n      /* Control number here must match the value in the group header */\n      .writeElement(\"1\");\n\nwriter.writeStartSegment(\"IEA\")\n      /* Count of groups here must match the actual count of GS/GE pairs */\n      .writeElement(String.valueOf(groupCount))\n      /* Control number here must match the value in the interchange header */\n      .writeElement(\"000000001\")\n      .writeEndSegment();\n\nwriter.endInterchange();\n\nwriter.close();\nstream.close();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxlate%2Fstaedi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxlate%2Fstaedi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxlate%2Fstaedi/lists"}