Package io.fluxcapacitor.common.api
Class Data<T>
java.lang.Object
io.fluxcapacitor.common.api.Data<T>
- Type Parameters:
T
- the type of the value held in this container
- All Implemented Interfaces:
SerializedObject<T>
A generic container for holding a value along with serialization metadata such as type, revision, and format.
This class is used extensively throughout Flux Capacitor to represent serialized or intermediate values (e.g.:
JsonNode
), often as part of SerializedMessage
,
SerializedDocument
, or key-value entries.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Custom format identifier for document data used inSerializedDocument
.static final String
Standard media type for JSON data. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs aData
instance with aSupplier
to support lazy access.Constructs aData
instance without a specific format (defaults to JSON).Constructs aData
instance with a fixed value and full metadata. -
Method Summary
Modifier and TypeMethodDescriptiondata()
Returns this instance (forSerializedObject
compatibility).boolean
Returns the effective format for the data, defaulting toJSON_FORMAT
ifformat
is null or "json".getValue()
Returns the deserialized value.int
hashCode()
<M> Data
<M> map
(ThrowingFunction<T, M> mapper) Transforms the value using a custom mapping function, while preserving serialization metadata.Replaces this instance with anotherData
object.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.common.api.SerializedObject
getRevision, getType
-
Field Details
-
JSON_FORMAT
Standard media type for JSON data.- See Also:
-
DOCUMENT_FORMAT
Custom format identifier for document data used inSerializedDocument
.- See Also:
-
-
Constructor Details
-
Data
@ConstructorProperties({"value","type","revision","format"}) public Data(T value, String type, int revision, String format) Constructs aData
instance with a fixed value and full metadata. -
Data
Constructs aData
instance without a specific format (defaults to JSON). -
Data
Constructs aData
instance with aSupplier
to support lazy access.
-
-
Method Details
-
getValue
Returns the deserialized value. This may trigger lazy loading via the supplier.- Returns:
- the deserialized object
-
getFormat
Returns the effective format for the data, defaulting toJSON_FORMAT
ifformat
is null or "json". -
equals
-
hashCode
public int hashCode() -
data
Returns this instance (forSerializedObject
compatibility).- Specified by:
data
in interfaceSerializedObject<T>
- Returns:
- the serialized payload
-
withData
Replaces this instance with anotherData
object. This method simply returns the provided argument (identity transform).- Specified by:
withData
in interfaceSerializedObject<T>
- Parameters:
data
- the new serialized payload- Returns:
- a new
SerializedObject
instance. May bethis
if unchanged
-
map
Transforms the value using a custom mapping function, while preserving serialization metadata.- Type Parameters:
M
- result type after mapping- Parameters:
mapper
- transformation function that may throw an exception- Returns:
- a new
Data<M>
with the mapped value and original serialization metadata
-