java.lang.Object
java.lang.Record
io.jooby.trpc.TrpcResponse<T>
- Type Parameters:
T- The type of the underlying data being returned.- Record Components:
data- The actual payload to serialize to the client, ornullif the procedure has no return value.
A standardized envelope for successful tRPC responses.
Unlike standard REST endpoints which might return raw JSON objects or arrays directly, the
tRPC protocol requires all successful procedure calls to wrap their actual payload inside a
specific JSON envelope (specifically, a data property).
This immutable record ensures that the Jooby routing engine serializes the returned Java
objects into the exact shape expected by the frontend @trpc/client, preventing parsing
errors on the browser side.
-
Constructor Summary
ConstructorsConstructorDescriptionTrpcResponse(@Nullable T data) Creates an instance of aTrpcResponserecord class. -
Method Summary
Modifier and TypeMethodDescription@Nullable Tdata()Returns the value of thedatarecord component.static <T> TrpcResponse<T> empty()Creates an empty tRPC success envelope.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static <T> TrpcResponse<T> of(T data) Wraps a non-null payload into a compliant tRPC success envelope.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
TrpcResponse
Creates an instance of aTrpcResponserecord class.- Parameters:
data- the value for thedatarecord component
-
-
Method Details
-
of
Wraps a non-null payload into a compliant tRPC success envelope.- Type Parameters:
T- The type of the data.- Parameters:
data- The actual data to return to the client (e.g., a specificMovieorList<Movie>).- Returns:
- A tRPC response envelope containing the provided data.
-
empty
Creates an empty tRPC success envelope.This is typically used by the Jooby routing engine to construct compliant network responses for procedures that return
voidor explicitly return no data.- Type Parameters:
T- The inferred type (usuallyVoidorObject).- Returns:
- A tRPC response envelope where the data property is explicitly null.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
data
Returns the value of thedatarecord component.- Returns:
- the value of the
datarecord component
-