Class JacksonConverter

java.lang.Object
org.axonframework.conversion.json.JacksonConverter
All Implemented Interfaces:
DescribableComponent, Converter

public class JacksonConverter extends Object implements Converter
A Converter implementation that uses Jackson's ObjectMapper to convert objects into and from a JSON format.
Since:
2.2.0
Author:
Allard Buijze, Mateusz Nowak, Steven van Beelen
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a JacksonConverter with a default ObjectMapper that finds and registers known modules.
    JacksonConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    Constructs a JacksonConverter with the given objectMapper.
    JacksonConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper, ChainingContentTypeConverter converter)
    Constructs a JacksonConverter with the given objectMapper and converter.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canConvert(Type sourceType, Type targetType)
    Indicates whether this Converter is capable of converting the given sourceType to the targetType.
    <T> T
    convert(Object input, Type targetType)
    Converts the given input object into an object of the given targetType.
    void
    Describe the properties of this DescribableComponent with the given descriptor.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.axonframework.conversion.Converter

    canConvert, convert
  • Constructor Details

    • JacksonConverter

      public JacksonConverter()
      Constructs a JacksonConverter with a default ObjectMapper that finds and registers known modules.
    • JacksonConverter

      public JacksonConverter(@Nonnull com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Constructs a JacksonConverter with the given objectMapper.
      Parameters:
      objectMapper - The mapper used to convert objects into and from a JSON format.
    • JacksonConverter

      @Internal public JacksonConverter(@Nonnull com.fasterxml.jackson.databind.ObjectMapper objectMapper, @Nonnull ChainingContentTypeConverter converter)
      Constructs a JacksonConverter with the given objectMapper and converter.

      This constructor should only be used when a specific ClassLoader should be give to the ChainingContentTypeConverter to ensure it loads the right set of ContentTypeConverters.

      Parameters:
      objectMapper - The mapper used to convert objects into and from a JSON format.
      converter - The converter used for simpler conversions.
  • Method Details

    • canConvert

      public boolean canConvert(@Nonnull Type sourceType, @Nonnull Type targetType)
      Description copied from interface: Converter
      Indicates whether this Converter is capable of converting the given sourceType to the targetType.
      Specified by:
      canConvert in interface Converter
      Parameters:
      sourceType - The type of data to convert from.
      targetType - The type of data to convert to.
      Returns:
      true if conversion is possible, false otherwise.
    • convert

      @Nullable public <T> T convert(@Nullable Object input, @Nonnull Type targetType)
      Description copied from interface: Converter
      Converts the given input object into an object of the given targetType.
      Specified by:
      convert in interface Converter
      Type Parameters:
      T - The target data type.
      Parameters:
      input - The value to convert.
      targetType - The type to convert the given input into.
      Returns:
      A converted version of the given input into the given targetType.
    • describeTo

      public void describeTo(@Nonnull ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.