Data Capture Context Deserializer

Defined in package com.scandit.datacapture.core.capture.serialization

Warning

The deserialization API is not yet stable and will still change over the coming releases.

Note

This deserializer is not thread-safe, subsequent calls for the same context have to be called on the same thread.

DataCaptureContextDeserializer
class DataCaptureContextDeserializer

Added in version 6.1.0

A deserializer to construct data capture contexts from JSON.

Related topics: Serialization.

DataCaptureContextDeserializer()
DataCaptureContextDeserializer(@NonNull FrameSourceDeserializer frameSourceDeserializer,
        @NonNull DataCaptureViewDeserializer viewDeserializer,
        @NonNull List<@NonNull DataCaptureModeDeserializer> modeDeserializers,
        @NonNull List<@NonNull DataCaptureComponentDeserializer> componentDeserializers)

Added in version 6.3.0

Creates a new deserializer object.

listener
@NonNull DataCaptureContextDeserializerListener getListener()
void setListener(@NonNull DataCaptureContextDeserializerListener value)

Added in version 6.1.0

The object informed about deserialization events.

avoidThreadDependencies
boolean getAvoidThreadDependencies()
void setAvoidThreadDependencies(boolean value)

Added in version 6.1.0

Avoids dependencies on other threads during contextFromJson() and updateContextFromJson(). This flag is not set by default which means the mentioned methods can have dependencies on other threads, the dependencies are as follows:

  • When the context specifies a capture mode array (even an empty one), the deserialization needs to synchronize with the context thread.

  • When the view specifies an overlay array (even an empty one), the deserialization needs to synchronize with the context thread.

These dependencies are necessary to ensure the consistency of the deserialization across multiple calls. In certain situations they can cause issues though because the context thread is waiting for another thread that is trying to execute a deserialization, resulting in a deadlock. This flag was introduced to allow to circumvent deadlocks in such cases.

If this flag is true, the deserializer can only be used with one context at a time and has to have created said context. Specifically this means the lifecycle is as follows:

  • avoidThreadDependencies is set to true.

  • The deserializer’s contextFromJson() is used to create a context.

  • The deserializer’s updateContextFromJson() is used zero or more times but only with the context previously created through the deserializer.

  • Every adding or removing of capture modes from this context is done through updateContextFromJson() (other changes like properties of capture modes etc. can be done through other ways).

It is possible to repeat this lifecycle over and over with different contexts, but it is essential that all calls involving a context are in sequence. It is not possible to create context A, update context A, create context B and then update context A again.

Just as without this flag the deserializer is not thread-safe and because of the above lifecycle all calls (not just the ones for the same context) have to be called on the same thread.

contextFromJson(jsonData)
@NonNull DataCaptureContextDeserializerResult contextFromJson(
        @NonNull String jsonData)

Added in version 6.1.0

Deserializes a data capture context from JSON.

An exception is thrown if the provided JSON does not contain required properties or contains properties of the wrong type.

updateContextFromJson(dataCaptureContext, view, components, jsonData)
@NonNull DataCaptureContextDeserializerResult updateContextFromJson(
        @NonNull DataCaptureContext dataCaptureContext,
        @NonNull DataCaptureView view,
        @NonNull List<@NonNull DataCaptureComponent> components,
        @NonNull String jsonData)

Added in version 6.3.0

Takes an existing data capture context and updates it by deserializing new or changed properties from JSON. See Updating from JSON for details of how updates are being done.

An exception is thrown if the provided JSON does not contain required properties or contains properties of the wrong type.