Class Jackson2Converter

java.lang.Object
org.axonframework.conversion.jackson2.Jackson2Converter
All Implemented Interfaces:
DescribableComponent, Converter

public class Jackson2Converter extends Object implements Converter
A Converter implementation for Jackson 2 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.
    Jackson2Converter(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    Constructs a JacksonConverter with the given objectMapper.
    Jackson2Converter(com.fasterxml.jackson.databind.ObjectMapper objectMapper, ChainingContentTypeConverter converter)
    Constructs a JacksonConverter with the given objectMapper and converter.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> @Nullable T
    convert(@Nullable 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

    convert
  • Constructor Details

    • Jackson2Converter

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

      public Jackson2Converter(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.
    • Jackson2Converter

      @Internal public Jackson2Converter(com.fasterxml.jackson.databind.ObjectMapper objectMapper, 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

    • convert

      public <T> @Nullable T convert(@Nullable Object input, 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(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.