Package discord4j.common
Class JacksonResources
- java.lang.Object
-
- discord4j.common.JacksonResources
-
public class JacksonResources extends Object
Provides a centralized Jackson 2.10ObjectMapperallowing customization and reuse across the application.
-
-
Field Summary
Fields Modifier and Type Field Description static Function<ObjectMapper,ObjectMapper>HANDLE_UNKNOWN_PROPERTIESA mapper ofObjectMapperto handle unknown properties without throwing errors.static Function<ObjectMapper,ObjectMapper>INITIALIZERA mapper ofObjectMapperwith all the required options for Discord4J operations.
-
Constructor Summary
Constructors Constructor Description JacksonResources()Deprecated.usecreate()JacksonResources(ObjectMapper objectMapper)Deprecated.usecreateFromObjectMapper(ObjectMapper)instead, but consider all Discord4J-related transformations are applied on the givenObjectMapperJacksonResources(Function<ObjectMapper,ObjectMapper> mapper)Deprecated.use one of the static factories and then callwithMapperFunction(Function)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JacksonResourcescreate()Create with a pre-configuredObjectMapperfor all Discord4J related operations.static JacksonResourcescreateFromObjectMapper(ObjectMapper objectMapper)Create based onObjectMapperapplying on it all changes required for Discord4J related operations.ObjectMappergetObjectMapper()Get theObjectMapperconfigured by this provider.JacksonResourceswithMapperFunction(Function<ObjectMapper,ObjectMapper> transformer)Return a newJacksonResourcesbased on this currentObjectMapperbut applying the given function.
-
-
-
Field Detail
-
INITIALIZER
public static final Function<ObjectMapper,ObjectMapper> INITIALIZER
A mapper ofObjectMapperwith all the required options for Discord4J operations.
-
HANDLE_UNKNOWN_PROPERTIES
public static final Function<ObjectMapper,ObjectMapper> HANDLE_UNKNOWN_PROPERTIES
A mapper ofObjectMapperto handle unknown properties without throwing errors.
-
-
Constructor Detail
-
JacksonResources
@Deprecated public JacksonResources()
Deprecated.usecreate()Create a defaultObjectMapperthat allows any field visibility, registers modules to handle Discord4J specific mappings and ignores unknown properties.
-
JacksonResources
@Deprecated public JacksonResources(Function<ObjectMapper,ObjectMapper> mapper)
Deprecated.use one of the static factories and then callwithMapperFunction(Function)Create a customObjectMapper, based on the defaults given byJacksonResources().- Parameters:
mapper- a Function to customize the ObjectMapper to be created
-
JacksonResources
@Deprecated public JacksonResources(ObjectMapper objectMapper)
Deprecated.usecreateFromObjectMapper(ObjectMapper)instead, but consider all Discord4J-related transformations are applied on the givenObjectMapperCreate with a pre-configuredObjectMapper. Using this will replace the recommended default and can lead to unexpected behavior and errors.- Parameters:
objectMapper- a pre-configured ObjectMapper to use
-
-
Method Detail
-
create
public static JacksonResources create()
Create with a pre-configuredObjectMapperfor all Discord4J related operations.
-
createFromObjectMapper
public static JacksonResources createFromObjectMapper(ObjectMapper objectMapper)
Create based onObjectMapperapplying on it all changes required for Discord4J related operations.
-
withMapperFunction
public JacksonResources withMapperFunction(Function<ObjectMapper,ObjectMapper> transformer)
Return a newJacksonResourcesbased on this currentObjectMapperbut applying the given function.- Parameters:
transformer- a mapper to enrich the currentObjectMapper- Returns:
- a new instance with the
transformerapplied
-
getObjectMapper
public ObjectMapper getObjectMapper()
Get theObjectMapperconfigured by this provider.- Returns:
- a Jackson ObjectMapper used to map POJOs to and from JSON format
-
-