Java Requires Chilkat v11.7.0+
Chilkat2 Java
Validate a QR Code Request
See more QR Code Examples
Demonstrates the validate operation, which examines a request without producing anything. The scope says how far to look: definition checks the options, capacity also checks that the data fits a QR symbol, and layout also checks the rendered size against the limits. The response has a validationStatus of valid or invalid, a list of checks, and findings[] describing what is wrong. A request that cannot be understood at all, such as one with a misspelled option, still makes the call fail in the usual way.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Formats;
import com.chilkatsoft.chilkat2.JsonObject;
public class ChilkatExample {
public static void main(String[] args) {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Formats fmt = new Formats();
JsonObject jsonOut = new JsonObject();
JsonObject json = new JsonObject();
json.updateString("target", "symbol");
json.updateString("validation.scope", "capacity");
json.updateString("payload.text", "https://www.chilkatsoft.com/barcode_overview.asp");
try {
fmt.qrCode("validate", json, jsonOut);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("status: " + jsonOut.stringOf("validationStatus"));
int n = jsonOut.sizeOfArray("checks");
for (int i = 0; i < n; i++) {
jsonOut.setI(i);
System.out.println(" " + jsonOut.stringOf("checks[i].name") + ": " + jsonOut.stringOf("checks[i].status"));
}
// The same text does not fit version 2 at error-correction level H.
json.updateInt("encoding.qr.maxVersion", 2);
json.updateString("encoding.qr.errorCorrection", "H");
try {
fmt.qrCode("validate", json, jsonOut);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("status: " + jsonOut.stringOf("validationStatus"));
n = jsonOut.sizeOfArray("checks");
for (int i = 0; i < n; i++) {
jsonOut.setI(i);
System.out.println(" " + jsonOut.stringOf("checks[i].name") + ": " + jsonOut.stringOf("checks[i].status"));
}
n = jsonOut.sizeOfArray("findings");
for (int i = 0; i < n; i++) {
jsonOut.setI(i);
System.out.println("finding: " + jsonOut.stringOf("findings[i].code") + " at " + jsonOut.stringOf("findings[i].path"));
System.out.println(" " + jsonOut.stringOf("findings[i].message"));
}
// Sample output:
// status: valid
// definition: passed
// capacity: passed
// layout: notApplicable
// status: invalid
// definition: passed
// capacity: failed
// layout: notApplicable
// finding: capacityExceeded at /payload
// the payload does not fit any admitted QR version at the selected error-correction level
}
}