Barcode-Lib4J requires Java 11+
Package de.vwsoft.barcodelib4j.oned
Java Class «GS1Validator» – GS1 data validation
java.lang.Object
de.vwsoft.barcodelib4j.oned.GS1Validator
Validates GS1 structured data and generates its human-readable representation.
This class is typically used when preparing input for GS1-128, GS1 DataMatrix, and GS1 QR Code.
Recommended Input Format (Simple Way)
For composing GS1 data, use this input format:
- No leading FNC1 character
- Each Application Identifier (AI) enclosed in parentheses
- FNC1 character after each AI-data pair as separator
String content = "(01)01234567890128" + fnc1 + "(15)251231" + fnc1 + "(10)ABC123" + fnc1; GS1Validator validator = new GS1Validator(content, fnc1);Key Points:
- For GS1 DataMatrix and GS1 QR Code use
(char)29
as FNC1. For GS1-128 use theImplCode128.FNC1
constant. - Unnecessary FNC1 characters will be removed automatically by the validator to ensure an optimal and space-saving structure of the encoded data.
- Parentheses around AIs are never encoded in the barcode but are displayed in the human-readable line.
- Tip: Place one of your variable-length AIs at the end of your data sequence to save one FNC1 character.
Alternative Input Formats
The validator also accepts pre-composed data (e.g., from user input, databases etc.):
- With parentheses:
(01)01234567890128(15)251231(10)ABC123
- Without parentheses:
01012345678901281525123110ABC123
- With or without leading FNC1
- Important: AIs with variable-length data must be terminated with FNC1 (unless at end)
SSCC/GTIN Check Digits (AI 00, 01, 02)
Use # as placeholder for automatic check digit calculation:
"(01)0123456789012#" // Check digit will be calculated "(01)01234567890128" // Check digit will be verifiedThe placeholder character is stored in
CHECKSUM_PLACEHOLDER
(static, non-final) and can
be customized if needed.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic char
Placeholder character that can be used in SSCC/GTIN numbers (AI 00, 01, 02) in place of the check digit to force its automatic calculation. -
Constructor Summary
ConstructorsConstructorDescriptionGS1Validator
(String content, char fnc1Char) Constructs a new instance and validates the provided GS1 data. -
Method Summary
Modifier and TypeMethodDescriptionReturns the validated data for encoding in a GS1 barcode.getText()
Returns the validated data in human-readable format.
-
Field Details
-
CHECKSUM_PLACEHOLDER
public static char CHECKSUM_PLACEHOLDERPlaceholder character that can be used in SSCC/GTIN numbers (AI 00, 01, 02) in place of the check digit to force its automatic calculation. As a static non-final variable it can be changed from the default ('#') if needed.
-
-
Constructor Details
-
GS1Validator
Constructs a new instance and validates the provided GS1 data.- Parameters:
content
- the GS1 data to validate (see class documentation for format options)fnc1Char
- the character used as FNC1 separator within the provided GS1 data- Throws:
BarcodeException
- if the content is empty or invalid according to GS1 standards
-
-
Method Details
-
getContent
Returns the validated data for encoding in a GS1 barcode.- Returns:
- the validated data for encoding in a GS1 barcode
-
getText
Returns the validated data in human-readable format.All Application Identifiers are enclosed in parentheses for readability. No FNC1 is included.
Example:
(01)01234567890128(15)251231(10)ABC123
- Returns:
- the validated data in human-readable format
-