Skip to main content
Version: v8001

Parse document class info

documentClassInfo identifies the document that was scanned. Its country, region, and documentType fields each carry two values:

  • id: a strongly-typed identifier, taken from the enum the SDK was built with
  • rawValue: the same classification as a plain string

Branch on id wherever you can, and reach for rawValue only when id is absent. The examples below assume result is the scanning result.

Read the ID fields​

id is an enum, so the compiler catches typos and your editor can autocomplete the values. Prefer it for all comparisons.

const classInfo = result.documentClassInfo;

console.log("Country:", classInfo?.country?.id); // "croatia"
console.log("Region:", classInfo?.region?.id); // "california", or absent
console.log("Document type:", classInfo?.documentType?.id); // "id"

if (classInfo?.country?.id === "croatia" && classInfo?.documentType?.id === "id") {
// Croatian identity card
}

Fall back to the raw value​

BlinkID receives support for new document classes over the air (OTA), after the SDK was built. When a document matches one of those classes, the enum has no matching value, so id is absent while rawValue is still populated.

Check id first, and compare rawValue only if id is absent. This keeps the enum path in place for every document the SDK already knows, and lets you ship support for a new class as a string comparison instead of an SDK upgrade.

const documentType = result.documentClassInfo?.documentType;

if (documentType?.id) {
handleKnownDocumentType(documentType.id);
} else if (documentType?.rawValue === "NEW VALUE AVAILABLE ONLY OTA") {
handleSpecialCase();
}

Write the fallback so an unrecognized rawValue is handled, not ignored. A class delivered over the air can reach your app before you have written any code for it.

Find the raw values​

See Supported documents for the browsable catalog.

Raw values are listed in the supported documents JSON, per document and per platform:

https://docs.microblink.com/blinkid/supported-docs/{version}/supported-documents.json

Each entry has an sdk object with a web, android, and ios key, and each of those holds the id and rawValue for country, region, and documentType. For example:

"sdk": {
"web": {
"country": { "id": "japan", "rawValue": "JAPAN" },
"region": null,
"documentType": { "id": null, "rawValue": "SPECIFIED RESIDENCE CARD" }
}
}

Absent values​

Two kinds of absence mean different things:

  • The whole component (country, region, or documentType) is absent: the document has no such classification. Most documents are not regional, so region is commonly absent.
  • The component is present but its id is absent: the class exists, was delivered over the air, and is only available as rawValue.

When the document could not be classified at all, documentClassInfo is either fully absent (web, Android) or niled (iOS).