Package io.jooby.trpc

Interface TrpcParser


public interface TrpcParser
The core JSON parsing SPI (Service Provider Interface) for tRPC.

This factory is implemented by Jooby's JSON modules (such as Jackson, Gson, JSON-B, or Avaje) and serves as the bridge between incoming tRPC network payloads and the application's Java objects.

Startup Optimization:

The Jooby Annotation Processor (APT) generates highly optimized routing code that relies on this interface. At application startup, the generated routes use this parser to eagerly resolve and cache type-specific TrpcDecoders. This ensures that during actual HTTP requests, payloads are deserialized with near-zero reflection overhead.

  • Method Summary

    Modifier and Type
    Method
    Description
    <T> TrpcDecoder<T>
    decoder(Type type)
    Resolves and caches a type-specific deserializer during route initialization.
    reader(byte[] payload, boolean isTuple)
    Creates a stateful, sequential reader for extracting tRPC arguments from a raw byte payload.
    reader(String payload, boolean isTuple)
    Creates a stateful, sequential reader for extracting tRPC arguments from a string payload.
  • Method Details

    • decoder

      <T> TrpcDecoder<T> decoder(Type type)
      Resolves and caches a type-specific deserializer during route initialization.

      This method is invoked by the APT-generated code when the application starts. By eagerly requesting a decoder for complex generic types, the framework avoids expensive reflection lookups during runtime request processing.

      Type Parameters:
      T - The expected Java type.
      Parameters:
      type - The target Java type (e.g., List<Movie>, User) to decode.
      Returns:
      A highly optimized decoder capable of parsing network payloads into the target type.
    • reader

      TrpcReader reader(byte[] payload, boolean isTuple)
      Creates a stateful, sequential reader for extracting tRPC arguments from a raw byte payload.

      Because tRPC network payloads can either be a single value or a JSON array (tuple) of multiple arguments, this reader manages the cursor position to sequentially hand off the correct JSON segment to the pre-resolved TrpcDecoders.

      Parameters:
      payload - The raw JSON byte array received from the network.
      isTuple - true if the payload is a JSON array representing multiple arguments; false if it represents a single, standalone argument.
      Returns:
      A reader for sequential argument extraction.
    • reader

      TrpcReader reader(String payload, boolean isTuple)
      Creates a stateful, sequential reader for extracting tRPC arguments from a string payload.

      Because tRPC network payloads can either be a single value or a JSON array (tuple) of multiple arguments, this reader manages the cursor position to sequentially hand off the correct JSON segment to the pre-resolved TrpcDecoders.

      Parameters:
      payload - The JSON string received from the network.
      isTuple - true if the payload is a JSON array representing multiple arguments; false if it represents a single, standalone argument.
      Returns:
      A reader for sequential argument extraction.