Complete Complex Barcode Examples

Complete Complex Barcode Examples

Complete workflows combine typed data creation, image generation, recognition, complex decoding, and field-by-field validation.

The complete source code for this article is available on GitHub:

View CompleteComplexBarcodeExamples.java

Generate, read, and decode Swiss QR

SwissQRCodetext sourceCodetext =
        createSwissQRCodetext();

ComplexBarcodeGenerator generator =
        new ComplexBarcodeGenerator(sourceCodetext);

generator.save(outputPath, BarCodeImageFormat.PNG);

Recognize and decode the result:

BarCodeReader reader =
        new BarCodeReader(outputPath, DecodeType.QR);

BarCodeResult[] results = reader.readBarCodes();

SwissQRCodetext decoded =
        ComplexCodetextReader.tryDecodeSwissQR(
                results[0].getCodeText()
        );

Process multiple complex barcodes

The example places a Swiss QR symbol and an HIBC QR LIC symbol into one composite image.

BufferedImage swissImage =
        new ComplexBarcodeGenerator(
                swissCodetext
        ).generateBarCodeImage();

BufferedImage hibcImage =
        new ComplexBarcodeGenerator(
                hibcCodetext
        ).generateBarCodeImage();

Read all supported carrier types and route each result to the corresponding complex decoder.

Verify round-trip business data

A strong regression test compares typed fields after decoding:

Assert.assertEquals(
        decodedCodetext.getPrimaryData(),
        sourceCodetext.getPrimaryData()
);

Assert.assertEquals(
        decodedCodetext.getSecondaryAndAdditionalData(),
        sourceCodetext.getSecondaryAndAdditionalData()
);

This detects data loss that a simple recognition check might miss.

Use end-to-end tests

Complete tests can detect:

  • missing required fields;
  • serialization errors;
  • image generation regressions;
  • carrier recognition regressions;
  • complex parsing regressions;
  • field conversion errors.

Recommendations

  • Validate both recognition and structured decoding.
  • Compare business fields, not only raw codetext.
  • Test documents that contain several complex barcodes.
  • Route each carrier to the appropriate decoder.
  • Keep representative end-to-end cases in automated tests.