Java Class «GS1Validator» – Validate GS1 structured data
Rules for the input format:
The first character in the input may or may not be an FNC1. The input may or may not include round brackets (parentheses), therefore both forms are equally accepted:
010123456789012815191231 (01)01234567890128(15)191231After validation, the human readable text returned by
getText()
includes all necessary
parentheses, regardless of the form in which the input was provided. The getContent()
method returns the data in a strictly formatted form suitable for representation in a barcode.
Rules for using FNC1 as AI separator:
- If the schema of a particular AI defines a fixed length for the encoded data, there's no need to indicate the end of the data. This also applies if the data unit is positioned at the end of the GS1 data structure. In both cases no FNC1 is required.
- If the schema of a particular AI defines a variable length for the encoded data, the end of the data must be marked with an FNC1. However, if the given AI schema does not allow round brackets within the data itself, an opening bracket "(" can be conveniently used instead of an FNC1 to introduce the next AI, as the bracket will be identified by the algorithm as not being part of the data and therefore replaced by an FNC1 automatically.
- If unsure whether an FNC1 should be used in a specific case, it's recommended to use it. The algorithm removes all unnecessary FNC1 characters to ensure an optimal and space-saving structure of the encoded data.
Rules for SSCC and GTIN (AI 00, 01, 02):
These special numbers must end with either a correct pre-computed check digit or with the
placeholder character defined by CHECKSUM_PLACEHOLDER
. Example:
(01)0123456789012#(15)191231If a placeholder is present, the missing check digit is automatically calculated and replaced. If a check digit is already present, it is verified, and a
BarcodeException
is thrown if it
is incorrect.-
Field Summary
Modifier and TypeFieldDescriptionstatic char
Wildcard character that can be used in AI 00 to AI 02 (SSCC/GTIN) in place of the checksum to force its automatic calculation. -
Constructor Summary
ConstructorDescriptionGS1Validator
(String content, char fnc1Char) Constructs a new instance and validates the specified content. -
Method Summary
Modifier and TypeMethodDescriptionReturns the validated raw data as it will be encoded in the barcode.getText()
Returns the validated data as human readable text.
-
Field Details
-
CHECKSUM_PLACEHOLDER
public static char CHECKSUM_PLACEHOLDERWildcard character that can be used in AI 00 to AI 02 (SSCC/GTIN) in place of the checksum to force its automatic calculation. The static variable can be set to any other character instead of the default ('#') if needed.
-
-
Constructor Details
-
GS1Validator
Constructs a new instance and validates the specified content.- Parameters:
content
- the content to be validatedfnc1Char
- the FNC1 character used as a separator within the content, and also used in the output returned bygetContent()
- Throws:
BarcodeException
- if the content is empty or invalid according to the GS1 standards
-
-
Method Details
-
getContent
Returns the validated raw data as it will be encoded in the barcode.Please note that the returned string does not include the leading FNC1 character, which is used to identify the GS1 data structure. This is because its "raw" value may differ from that of the FNC1 character used as a separator. However, a leading FNC1 character is automatically added by
GS1-128
andTwoDCode
prior to encoding.- Returns:
- the validated raw data as it will be encoded in the barcode
-
getText
Returns the validated data as human readable text.Application Identifier (AI) numbers are enclosed in round brackets (parentheses).
- Returns:
- the validated data as human readable text
-