GS1 Digital Link
Overview
The parser supports version 1.4.1 of the GS1 Digital Link standard for uncompressed URIs. The latest version of the Digital Link standard is described in GS1 Digital Link Standard: URI Syntax.
Sample usage for GS1 Digital Link parser and Barcode Capture
First, you need to create a DataCaptureContext, access a Camera and create GS1 parser:
DataCaptureContext dataCaptureContext = DataCaptureContext.forLicenseKey(SCANDIT_LICENSE_KEY);
Camera camera = Camera.getDefaultCamera(BarcodeCapture.createRecommendedCameraSettings());
camera.applySettings(BarcodeCapture.createRecommendedCameraSettings());
dataCaptureContext.setFrameSource(camera);
camera.switchToDesiredState(FrameSourceState.ON);
BarcodeCaptureSettings barcodeCaptureSettings = new BarcodeCaptureSettings();
BarcodeCapture barcodeCapture = BarcodeCapture.forDataCaptureContext(dataCaptureContext, barcodeCaptureSettings);
Parser parser = Parser.forFormat(dataCaptureContext, ParserDataFormat.GS1_DIGITAL_LINK);
Then, you need to implement BarcodeCaptureListener:
class MyBarcodeCaptureListener implements BarcodeCaptureListener {
@Override
public void onBarcodeScanned(
@NonNull BarcodeCapture barcodeCapture,
@NonNull BarcodeCaptureSession session,
@NonNull FrameData frameData
) {
if (session.getNewlyRecognizedBarcodes().isEmpty()) return;
Barcode barcode = session.getNewlyRecognizedBarcodes().get(0);
String data = barcode.getData();
try {
ParsedData parsedData = parser.parseString(data);
/*
* Extract the fields relevant to your use case. Below, for example, we extract a batch/lot number,
* which has the type String, and an expiry date, which is represented as a map with keys
* "year", "month", "day".
*/
String serialNumber = (String) parsedData.getFieldsByName().get("10").getParsed();
Map<String, Object> expiryDate = (Map<String, Object>) parsedData.getFieldsByName().get("17").getParsed();
int year = expiryDate.get("year");
int month = expiryDate.get("month");
int day = expiryDate.get("day");
// Do something with the extracted fields.
} catch (RuntimeException e) {
message = e.getMessage();
}
// Other callbacks omitted for brevity.
}
Finally, add the listener to the mode to receive scan results:
barcodeCapture.addListener(new MyBarcodeCaptureListener());
For details, go to the API docs.
Examples
Parsing the following code (without the quotes):
"https://id.gs1.org/01/09506000134352/10/PX8L/21/1BAAAA2BB3?17=141100"
will result in the following JSON output:
[
{
"name" : "01",
"parsed" : {
"GTIN": "09506000134352"
},
"rawString" : "09506000134352"
},
{
"name" : "10",
"parsed" : "PX8L",
"rawString" : "PX8L"
},
{
"name" : "21",
"parsed" : "1BAAAA2BB3",
"rawString" : "1BAAAA2BB3"
},
{
"name" : "17",
"parsed" : {
"month" : 11,
"year" : 2014
},
"rawString" : "141100"
},
{ "name" : "humanReadableString",
"parsed" : "(01)09506000134352(10)PX8L(21)1BAAAA2BB3(17)141100",
"rawString" : "(01)09506000134352(10)PX8L(21)1BAAAA2BB3(17)141100",
}
]
Exposed Fields
The name of the fields correspond to the AI number. The following fields have their content parsed. Fields which are not in this list can still be accessed, but only the raw string is available.
“00”: parsed data is a dictionary, always contains alphanumeric subfields “extensionDigit” and “SSCC”.
“01”, “02”: parsed data is a dictionary, always contains “GTIN” field. It sometimes contains integer field “indicator” (if non-zero).
“10”: parsed data is a string (batch/lot number)
“11”, “12”, “13”, “15”, “16”, “17”: parsed data is a dictionary, always contains integer fields “year” (YYYY), “month” (MM) and sometimes “day” (DD)
“20”: parsed data is an integer (the variant)
“21”: parsed data is a string (the serial number)
“30”: parsed data is an integer (count of items, between 0 and 99999999)
“31ab”, “32ab”, “33ab”, “34ab”, “35ab”, “36ab” for some numbers a and b: These AI’s are represented by two fields in our result: The field “31ab” and the fields “31ax”. For example: The AI “3222” has the fields “3222” and “322x” The parsed data is a string of the floating point number (e.g. “3202000150” has the parsed data “1.50”)
“37”: parsed data is an integer (count of items, between 0 and 99999999)
“400”: parsed data is a string (customer’s purchase order number)
“401”: parsed data is a string (global identification number for consignment)
“402”: parsed data is a string (global shipment identification number)
“403”: parsed data is a string (routing code)
“410”: parsed data is a string (ship to / deliver to global location number)
“411”: parsed data is a string (bill to / invoice to global location number)
“412”: parsed data is a string (purchased from global location number)
“413”: parsed data is a string (ship for / deliver for - forward to global location number)
“414”: parsed data is a string (identification of a physical location - global location number)
“415”: parsed data is a string (global location number of the invoicing party)
“416”: parsed data is a string (global location number of the production or service location)
“420”: parsed data is a string (ship to / deliver to postal code within a single postal authority)
“421”: parsed data is a dictionary, always contains “countryCode” and “postalCode” fields (ship to / deliver to postal code with three-digit ISO country code)
“422”: parsed data is a string (country of origin of a trade item / ISO 3166)
“423”: parsed data is an array (countries of initial processing / ISO 3166)
“424”: parsed data is a string (country of processing / ISO 3166)
“425”: parsed data is an array (countries of disassembly / ISO 3166)
“426”: parsed data is a string (country covering full process chain / ISO 3166)
“427”: parsed data is a string (country subdivision of origin code for a trade item / ISO 3166-2)
“7003”: parsed data is a dictionary, always contains integer fields “year” (YYYY), “month” (MM), “day” (DD), “hour” (HH), “minute” (MM).
“8017”: parsed data is a dictionary, always contains string subfield “GSRN”.
“8018”: parsed data is a dictionary, always contains string subfield “GSRN”.
“91”-“99”: parsed data is a string
Extensions
Arbitrary fields can be set using the url parameters, but no further parsing is performed by the parser. In this case, the (key, value) pairs are exposed directly as strings in the parsed results without further parsing.
Parser Options
Following options can be set to fine-tune the behavior of the parser:
- “strictMode”: boolean (default:false)
Controls the strictness of the parser. If true, only canonical URIs will be parsed and additionally the parsing of each field will follow the rules described for GS1 AI parsing.
- “outputHumanReadableString”: boolean (default: false)
Adds the additional field “humanReadableString” at the end of the resulting JSON string. This field contains the code in human readable form (i.e. AI number encapsulated in parenthesis).