Skip to main content
Package: com.coinbase.cdp.core
Utility class for parsing Server-Sent Events with support for discriminated unions. Handles two discrimination patterns:
  1. Data-level discrimination: The discriminator (e.g., ‘type’) is inside the JSON data payload. Jackson’s polymorphic deserialization handles this automatically.
  2. Event-level discrimination: The discriminator (e.g., ‘event’) is at the SSE envelope level. This requires constructing the full SSE envelope for Jackson to process.

Method Details

parseEventLevelUnion

Parse an SSE event using event-level discrimination. Constructs the full SSE envelope object with event, data, id, and retry fields, then deserializes it to the target union type. Type Parameters: T - The target type Parameters: eventType (String) - The SSE event type (from event: field) data (String) - The SSE data content (from data: field) id (String) - The SSE event ID (from id: field), may be null retry (Long) - The SSE retry value (from retry: field), may be null unionClass (Class<T>) - The target union class discriminatorProperty (String) - The property name used for discrimination (e.g., “event”) Returns: T - The deserialized object

parseDataLevelUnion

Parse an SSE event using data-level discrimination. Simply parses the data field as JSON and deserializes it to the target type. Jackson’s polymorphic deserialization handles the discrimination automatically. Type Parameters: T - The target type Parameters: data (String) - The SSE data content (from data: field) valueType (Class<T>) - The target type Returns: T - The deserialized object

isEventLevelDiscrimination

Determines if the given discriminator property indicates event-level discrimination. Event-level discrimination occurs when the discriminator is an SSE envelope field. Parameters: discriminatorProperty (String) - The discriminator property name Returns: boolean - true if event-level discrimination, false otherwise

findDiscriminatorProperty

Attempts to find the discriminator property from the union class’s Jackson annotations. Parameters: unionClass (Class<?>) - The union class to inspect Returns: Optional<String> - The discriminator property name, or empty if not found