Barcode-Lib4J requires Java 11+

Java Class «GS1Validator»  –  GS1 data validation

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

public class GS1Validator extends Object
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:

  1. No leading FNC1 character
  2. Each Application Identifier (AI) enclosed in parentheses
  3. FNC1 character after each AI-data pair as separator
Example:
   String content = "(01)01234567890128" + fnc1 +
                    "(15)251231" + fnc1 +
                    "(10)ABC123" + fnc1;
   GS1Validator validator = new GS1Validator(content, fnc1);
 
Key Points:
  1. For GS1 DataMatrix and GS1 QR Code use (char)29 as FNC1. For GS1-128 use the ImplCode128.FNC1 constant.
  2. Unnecessary FNC1 characters will be removed automatically by the validator to ensure an optimal and space-saving structure of the encoded data.
  3. Parentheses around AIs are never encoded in the barcode but are displayed in the human-readable line.
  4. 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 verified
 
The placeholder character is stored in CHECKSUM_PLACEHOLDER (static, non-final) and can be customized if needed.
  • Field Summary

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

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

    Modifier and Type
    Method
    Description
    Returns the validated data for encoding in a GS1 barcode.
    Returns the validated data in human-readable format.

    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
      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. As a static non-final variable it can be changed from the default ('#') if needed.
  • Constructor Details

    • GS1Validator

      public GS1Validator(String content, char fnc1Char) throws BarcodeException
      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

      public String getContent()
      Returns the validated data for encoding in a GS1 barcode.
      Returns:
      the validated data for encoding in a GS1 barcode
    • getText

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