Interface ConverterSession

All Known Implementing Classes:
BsonParserSession, BsonSerializerSession, CborParserSession, CborSerializerSession, CsvParserSession, CsvSerializerSession, HjsonParserSession, HjsonSerializerSession, HoconParserSession, HoconSerializerSession, HtmlDocSerializerSession, HtmlParserSession, HtmlSchemaDocSerializerSession, HtmlSchemaSerializerSession, HtmlSerializerSession, HtmlStrippedDocSerializerSession, IniParserSession, IniSerializerSession, InputStreamParserSession, JcsSerializerSession, Json5lParserSession, Json5lSerializerSession, Json5ParserSession, Json5SerializerSession, JsonlParserSession, JsonlSerializerSession, JsonParserSession, JsonSchemaGeneratorSession, JsonSchemaSerializerSession, JsonSerializerSession, MarkdownDocParserSession, MarkdownDocSerializerSession, MarkdownParserSession, MarkdownSerializerSession, MarshallingSession, MarshallingTraverseSession, MockRestRequest, MsgPackParserSession, MsgPackSerializerSession, OpenApiParserSession, OpenApiSerializerSession, OutputStreamSerializerSession, ParquetParserSession, ParquetSerializerSession, ParserSession, PlainTextParserSession, PlainTextSerializerSession, RdfParserSession, RdfSerializerSession, RdfStreamParserSession, RdfStreamSerializerSession, ReaderParserSession, RestRequest, SerializerSession, SoapXmlSerializerSession, SseParserSession, SseSerializerSession, TomlParserSession, TomlSerializerSession, UonParserSession, UonSerializerSession, UrlEncodingParserSession, UrlEncodingSerializerSession, WriterSerializerSession, XmlDocSerializerSession, XmlParserSession, XmlSerializerSession, YamlParserSession, YamlSerializerSession

public interface ConverterSession
Provides contextual objects to Conversion functions at call time.

A ConverterSession is passed through the Conversion.to(Object, Object, ConverterSession, Class[]) method and allows conversion lambdas to retrieve session-scoped objects such as a TimeZone, Locale, or media type without requiring those objects to be captured in the lambda closure.

Implementations look up contextual objects by type (and optionally by name). If no matching object is registered for the requested type the method returns Optional.empty().

Example:

// A Conversion lambda that reads TimeZone from the session. Conversion<String, Calendar> conv = (in, memberOf, session, args) -> { var tz = session != null ? session.get(TimeZone.class).orElse(TimeZone.getDefault()) : TimeZone.getDefault(); // ... parse in using tz ... return null; };

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> Optional<T>
    get(Class<T> c)
    Returns a contextual object of the specified type, or Optional.empty() if none is registered.
    default <T> Optional<T>
    get(String name, Class<T> c)
    Returns a named contextual object of the specified type, or Optional.empty() if none is registered.
  • Method Details

    • get

      <T> Optional<T> get(Class<T> c)
      Returns a contextual object of the specified type, or Optional.empty() if none is registered.
      Type Parameters:
      T - The object type.
      Parameters:
      c - The object type to look up.
      Returns:
      The contextual object wrapped in an Optional, or Optional.empty() if not available.
    • get

      default <T> Optional<T> get(String name, Class<T> c)
      Returns a named contextual object of the specified type, or Optional.empty() if none is registered.

      The default implementation ignores the name and delegates to get(Class). Override this method when multiple objects of the same type need to be distinguished by name.

      Type Parameters:
      T - The object type.
      Parameters:
      name - The object name, or null to match any.
      c - The object type to look up.
      Returns:
      The contextual object wrapped in an Optional, or Optional.empty() if not available.