Class ComponentMatcher

java.lang.Object
org.eclipse.yasson.internal.ComponentMatcher

public class ComponentMatcher extends Object
Searches for a registered components or Serializer for a given type.
  • Field Details

    • jsonbContext

      private final JsonbContext jsonbContext
    • genericComponents

      private volatile boolean genericComponents
      Flag for searching for generic serializers and adapters in runtime.
    • userComponents

      private final ConcurrentMap<Type,ComponentBindings> userComponents
  • Constructor Details

    • ComponentMatcher

      ComponentMatcher(JsonbContext context)
      Create component matcher.
      Parameters:
      context - mandatory
  • Method Details

    • init

      void init()
      Called during context creation, introspecting user components provided with JsonbConfig.
    • getBindingInfo

      private ComponentBindings getBindingInfo(Type type)
    • addSerializer

      private void addSerializer(Type bindingType, SerializerBinding<?> serializer)
    • addDeserializer

      private void addDeserializer(Type bindingType, DeserializerBinding<?> deserializer)
    • addAdapter

      private void addAdapter(Type bindingType, AdapterBinding adapter)
    • registerGeneric

      private void registerGeneric(Type bindingType)
      If type is not parametrized runtime component resolution doesn't has to happen.
      Parameters:
      bindingType - component binding type
    • getSerializerBinding

      public Optional<SerializerBinding<?>> getSerializerBinding(Type propertyRuntimeType, ComponentBoundCustomization customization)
      Lookup serializer binding for a given property runtime type.
      Parameters:
      propertyRuntimeType - runtime type of a property
      customization - with component info
      Returns:
      serializer optional
    • getDeserializerBinding

      public Optional<DeserializerBinding<?>> getDeserializerBinding(Type propertyRuntimeType, ComponentBoundCustomization customization)
      Lookup deserializer binding for a given property runtime type.
      Parameters:
      propertyRuntimeType - runtime type of a property
      customization - customization with component info
      Returns:
      serializer optional
    • getSerializeAdapterBinding

      public Optional<AdapterBinding> getSerializeAdapterBinding(Type propertyRuntimeType, ComponentBoundCustomization customization)
      Get components from property model (if declared by annotation and runtime type matches), or return components searched by runtime type.
      Parameters:
      propertyRuntimeType - runtime type not null
      customization - customization with component info
      Returns:
      components info if present
    • getDeserializeAdapterBinding

      public Optional<AdapterBinding> getDeserializeAdapterBinding(Type propertyRuntimeType, ComponentBoundCustomization customization)
      Get components from property model (if declared by annotation and runtime type matches), or return components searched by runtime type.
      Parameters:
      propertyRuntimeType - runtime type not null
      customization - customization with component info
      Returns:
      components info if present
    • searchComponentBinding

      private <T extends AbstractComponentBinding> Optional<T> searchComponentBinding(Type runtimeType, Function<ComponentBindings,T> supplier)
    • getMatchingBinding

      private <T> Optional<T> getMatchingBinding(Type runtimeType, ComponentBindings binding, Function<ComponentBindings,T> supplier)
    • matches

      private boolean matches(Type runtimeType, Type componentBindingType)
    • matchTypeArguments

      private boolean matchTypeArguments(ParameterizedType requiredType, ParameterizedType componentBound)
      If runtimeType to adapt is a ParametrizedType, check all type args to match against components args.
    • introspectAdapterBinding

      AdapterBinding introspectAdapterBinding(Class<? extends jakarta.json.bind.adapter.JsonbAdapter> adapterClass, jakarta.json.bind.adapter.JsonbAdapter instance)
      Introspect components generic information and put resolved types into metadata wrapper.
      Parameters:
      adapterClass - class of an components
      instance - components instance
      Returns:
      introspected info with resolved typevar types.
    • introspectDeserializerBinding

      DeserializerBinding introspectDeserializerBinding(Class<? extends jakarta.json.bind.serializer.JsonbDeserializer> deserializerClass, jakarta.json.bind.serializer.JsonbDeserializer instance)
      If an instance of deserializerClass is present in context and is bound for same type, return that instance. Otherwise create new instance and set it to context.
      Parameters:
      deserializerClass - class of deserializer
      instance - instance to use if not cached already
      Returns:
      wrapper used in property models
    • introspectSerializerBinding

      SerializerBinding introspectSerializerBinding(Class<? extends jakarta.json.bind.serializer.JsonbSerializer> serializerClass, jakarta.json.bind.serializer.JsonbSerializer instance)
      If an instance of serializerClass is present in context and is bound for same type, return that instance. Otherwise create new instance and set it to context.
      Parameters:
      serializerClass - class of deserializer
      instance - instance to use if not cached
      Returns:
      wrapper used in property models
    • resolveTypeArg

      private Type resolveTypeArg(Type adapterTypeArg, Type adapterType)