Class GrpcMetaDataConverter

java.lang.Object
org.axonframework.axonserver.connector.util.GrpcMetaDataConverter

public class GrpcMetaDataConverter extends Object
Utility class for converting gRPC MetaData entries into a Java Map and vice versa.

To optimize communication and minimize the loss of data structure, the MetaDataValue entries used in gRPC distinguish between numerical values (double or long), Strings, booleans and arbitrary objects. The latter group is converted to and from a byte[] using the configured Serializer.

Since:
4.0
Author:
Marc Gathier
  • Constructor Details

    • GrpcMetaDataConverter

      public GrpcMetaDataConverter(Serializer serializer)
      Initialize the converter, using the given serializer to serialize Objects.
      Parameters:
      serializer - the Serializer to serialize objects with
  • Method Details

    • convertToMetaDataValue

      public io.axoniq.axonserver.grpc.MetaDataValue convertToMetaDataValue(Object value)
      Convert the given value into a MetaDataValue, attempting to maintain the source type as much as possible in the returned MetaDataValue.
      • A CharSequence (such as String) is stored as a 'string'
      • A Float or Double values is represented as a 'double'
      • A Number that is not a Double or Float is represented as a 'sint64'
      • A Boolean is represented as a 'bool'
      • Any other object is serialized and stored as bytes
      Parameters:
      value - the Object to convert into a MetaDataValue
      Returns:
      a MetaDataValue representing the given value
    • convert

      public MetaData convert(Map<String,io.axoniq.axonserver.grpc.MetaDataValue> metaDataMap)
      Convert the given Map of MetaDataValues to a Map containing the Java representations of each of those values.

      See convertToMetaDataValue(Object) for details about the mapping.

      Parameters:
      metaDataMap - a Map containing MetaDataValue representations of each MetaData key
      Returns:
      a MetaData map containing the same keys, referencing to the Java representation of each corresponding value in the given metaDataMap
    • convertFromMetaDataValue

      public Object convertFromMetaDataValue(io.axoniq.axonserver.grpc.MetaDataValue value)
      Convert the given MetaDataValue to its Java representation.

      See convertToMetaDataValue(Object) for details about the mapping.

      Parameters:
      value - the MetaDataValue to convert to its Java representation
      Returns:
      an Object representing the same value
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object