PANTHEUM Open-source parsers
Last updated: Version: 1.1.0

Getting started with GAIA Library

This page takes you from an empty project to a parsed, validated barcode. For more detail, see the full guides.

1. Add GAIA to your project

GAIA is on Maven Central. Add the dependency:

<dependency>
    <groupId>tools.pantheum</groupId>
    <artifactId>gaia</artifactId>
    <version>1.1.0</version>
</dependency>

For Gradle, use implementation("tools.pantheum:gaia:1.1.0"). The download page also has sbt and Groovy versions.

That is the only dependency you need to add. GAIA's one runtime dependency, Jackson Databind, comes with it. If your build already sets a Jackson version, GAIA uses that version.

2. Parse something

// Create one parser and reuse it. It is thread-safe and loads its data once.
private static final GaiaParser PARSER = new GaiaParser();

ParseResult result = PARSER.parse("01095060001343521726123110LOT-001");

System.out.println("valid : " + result.isValid());
System.out.println("HRI   : " + result.getAiObject().toHriString());
valid : true
HRI   : (01)09506000134352 (17)261231 (10)LOT-001

3. Read the result

Look up an AI by its code rather than by its position:

GS1AIObjectElement expiry = result.getAiObject().get("17");   // null if absent
String date = expiry.getInterpretation("DATE_VALUE").getValue(); // "31/12/2026"

4. Handle bad data

Invalid data is a normal result, not an exception. parse never throws because of bad GS1 data:

ParseResult bad = PARSER.parse("0109506000134350");   // the last digit should be 2
bad.isValid();      // false
bad.getErrors();    // [GE-C003] Check digit validation failed for AI (01) ...

Write your logic against the error ID returned by getId(), never against the message text. Messages are translated, and their wording can change.

5. Watch out for the GS separator

A variable-length AI continues until it reaches a GS character (0x1D, FNC1) or the end of the string. If another AI follows, the separator is required. Without it, you don't get an error. You get a wrong result that looks valid:

PARSER.parse("0109506000134352" + "10LOT-ABC" + "\u001D" + "21SN-98765");
// (01)09506000134352 (10)LOT-ABC (21)SN-98765

PARSER.parse("0109506000134352" + "10LOT-ABC" + "21SN-98765");
// (01)09506000134352 (10)LOT-ABC21SN-98765    valid, and the serial is lost

Read scanner bytes as ISO-8859-1 so that 0x1D isn't lost.

6. Scanner prefixes and Digital Link

ParseResult scan = PARSER.parse("]C1010950600013435210LOT-ABC");
scan.getDataCarrier().getDataCarrierType();      // GS1_128

ParseResult dl = PARSER.parse("https://example.com/01/09506000134352/10/LOT-ABC?17=271231");
dl.getAiObject().getCanonicalDigitalLink();      // https://id.gs1.org/01/09506000134352/10/LOT-ABC?17=271231
dl.getAiObject().toElementString();              // 010950600013435210LOT-ABC<GS>17271231

7. Build an element string or a URI

String element = GaiaBuilder.create()
        .ai("01", "09506000134352")
        .ai("10", "LOT-ABC")
        .buildElementString();            // 010950600013435210LOT-ABC

String uri = GaiaBuilder.create()
        .ai("01", "09506000134352")
        .ai("10", "LOT-ABC")
        .buildDigitalLinkUri(BuilderDigitalLinkConfig.builder().domain("id.acme.com").build());
// https://id.acme.com/01/09506000134352/10/LOT-ABC

8. Change the language

ParseConfig config = ParseConfig.builder()
        .language(Language.FRENCH)
        .dateEndian(DateEndian.BIG)
        .dateSeparator(DateSeparator.HYPHEN)
        .build();

PARSER.parse("01095060001343521726123110LOT-001", config)
      .getAiObject().get("17").getDescription();
// "Date limite d'utilisation (AAMMJJ)"

9. Get JSON

String json = GaiaJson.toJson(result, GaiaJson.Verbosity.COMPACT);
{"product":"Gaia","version":"1.1.0","operation":"parse","valid":true,
 "elements":[{"ai":"01","title":"GTIN","value":"09506000134352"},
             {"ai":"10","title":"BATCH/LOT","value":"LOT-ABC"}],"errors":[]}

Next steps