Here you learn how to manually validate a QrInvoice object and how to get details out of the validation result.

import ch.codeblock.qrinvoice.model.QrInvoice;
import ch.codeblock.qrinvoice.model.builder.QrInvoiceBuilder;
import ch.codeblock.qrinvoice.model.validation.QrInvoiceValidator;
import ch.codeblock.qrinvoice.model.validation.ValidationResult;

import java.util.List;

// ...

final QrInvoice qrInvoice = // create using QrInvoiceBuilder;

// now set some invalid data

// creditor must be set, this will result in a validation error
qrInvoice.getCreditorInformation().getCreditor().setName("");
// set an unsupported QR Type
qrInvoice.getHeader().setQrType("foo");

final ValidationResult validationResult = QrInvoiceValidator.create().validate(qrInvoice);
if(validationResult.hasErrors()) {
    final String validationErrorSummary = validationResult.getValidationErrorSummary();
    System.out.println(validationErrorSummary);

    // access each ValidationError on its own
    final List<ValidationResult.ValidationError> errors = validationResult.getErrors();
    // ...
}

The snippet above will print a summary of the validation errors.

QrInvoice has validation errors:
1. 'header.qrType' has invalid value 'foo'
    => Fixed length: three-digit, alphanumeric
    => Unambiguous indicator for the Swiss QR Code. Fixed value “SPC” (Swiss Payments Code)
2. 'creditorinformation.creditor.name' has invalid value ''
    => First name (optional, if available) + last name or company name
    => Maximum 70 characters permitted

Of course, you can get the details for each validation error

// access each ValidationError on its own
final List<ValidationResult.ValidationError> errors = validationResult.getErrors();
for (final ValidationResult.ValidationError error : errors) {
    System.out.println(error.getDataPath());
    System.out.println(error.getValue());
    for (final String errorMsgKey : error.getErrorMsgKeys()) {
        System.out.println(errorMsgKey);
    }
}
// ...
// ...