Class JacksonConverter
- All Implemented Interfaces:
DescribableComponent,Converter
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
ConstructorsConstructorDescriptionConstructs aJacksonConverterwith a defaultObjectMapperthatfinds and registers known modules.JacksonConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Constructs aJacksonConverterwith the givenobjectMapper.JacksonConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper, ChainingContentTypeConverter converter) Constructs aJacksonConverterwith the givenobjectMapperandconverter. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanConvert(Type sourceType, Type targetType) Indicates whether thisConverteris capable of converting the givensourceTypeto thetargetType.<T> TConverts the giveninputobject into an object of the giventargetType.voiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.conversion.Converter
canConvert, convert
-
Constructor Details
-
JacksonConverter
public JacksonConverter()Constructs aJacksonConverterwith a defaultObjectMapperthatfinds and registers known modules. -
JacksonConverter
public JacksonConverter(@Nonnull com.fasterxml.jackson.databind.ObjectMapper objectMapper) Constructs aJacksonConverterwith the givenobjectMapper.- 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 aJacksonConverterwith the givenobjectMapperandconverter.This constructor should only be used when a specific
ClassLoadershould be give to theChainingContentTypeConverterto ensure it loads the right set ofContentTypeConverters.- Parameters:
objectMapper- The mapper used to convert objects into and from a JSON format.converter- The converter used for simpler conversions.
-
-
Method Details
-
canConvert
Description copied from interface:ConverterIndicates whether thisConverteris capable of converting the givensourceTypeto thetargetType.- Specified by:
canConvertin interfaceConverter- Parameters:
sourceType- The type of data to convert from.targetType- The type of data to convert to.- Returns:
trueif conversion is possible,falseotherwise.
-
convert
Description copied from interface:ConverterConverts the giveninputobject into an object of the giventargetType. -
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods 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
DescribableComponentimplementation 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 thedescribeTomethod, 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:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-