Package io.jooby.trpc

Record Class TrpcResponse<T>

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, or null if the procedure has no return value.

public record TrpcResponse<T>(@Nullable T data) extends Record
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

    Constructors
    Constructor
    Description
    TrpcResponse(@Nullable T data)
    Creates an instance of a TrpcResponse record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable T
    Returns the value of the data record component.
    static <T> TrpcResponse<T>
    Creates an empty tRPC success envelope.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    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 String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • TrpcResponse

      public TrpcResponse(@Nullable T data)
      Creates an instance of a TrpcResponse record class.
      Parameters:
      data - the value for the data record component
  • Method Details

    • of

      public static <T> TrpcResponse<T> of(T data)
      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 specific Movie or List<Movie>).
      Returns:
      A tRPC response envelope containing the provided data.
    • empty

      public static <T> TrpcResponse<T> 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 void or explicitly return no data.

      Type Parameters:
      T - The inferred type (usually Void or Object).
      Returns:
      A tRPC response envelope where the data property is explicitly null.
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • data

      public @Nullable T data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component