Barcode-Lib4J requires Java 9+

Java Class «GS1Validator»  –  Validate GS1 structured data

java.lang.Object
de.vwsoft.barcodelib4j.oned.GS1Validator

public class GS1Validator extends Object
Validates GS1 structured data and generates the corresponding human readable representation. The class performs tasks such as calculating check digits for GTIN and SSCC and verifying the length and format of data for compliance with the respective Application Identifiers (AI).

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)191231
 
After 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)191231
If 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

    Fields
    Modifier and Type
    Field
    Description
    static 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

    Constructors
    Constructor
    Description
    GS1Validator(String content, char fnc1Char)
    Constructs a new instance and validates the specified content.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the validated raw data as it will be encoded in the barcode.
    Returns the validated data as human readable text.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CHECKSUM_PLACEHOLDER

      public static char CHECKSUM_PLACEHOLDER
      Wildcard 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

      public GS1Validator(String content, char fnc1Char) throws BarcodeException
      Constructs a new instance and validates the specified content.
      Parameters:
      content - the content to be validated
      fnc1Char - the FNC1 character used as a separator within the content, and also used in the output returned by getContent()
      Throws:
      BarcodeException - if the content is empty or invalid according to the GS1 standards
  • Method Details

    • getContent

      public String 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 and TwoDCode prior to encoding.

      Returns:
      the validated raw data as it will be encoded in the barcode
    • getText

      public String 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