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 defaultObjectMapperconstructed by theJsonMapper.builder(), thatfinds and registers known modules.JacksonConverter(tools.jackson.databind.ObjectMapper objectMapper) Constructs aJacksonConverterwith the givenobjectMapper.JacksonConverter(tools.jackson.databind.ObjectMapper objectMapper, ChainingContentTypeConverter converter) Constructs aJacksonConverterwith the givenobjectMapperandconverter. -
Method Summary
Modifier and TypeMethodDescription<T> @Nullable TConverts the giveninputobject into an object of the giventargetType.voiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.
-
Constructor Details
-
JacksonConverter
public JacksonConverter()Constructs aJacksonConverterwith a defaultObjectMapperconstructed by theJsonMapper.builder(), thatfinds and registers known modules. -
JacksonConverter
public JacksonConverter(tools.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(tools.jackson.databind.ObjectMapper objectMapper, 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
-
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.
-