Package org.dizitart.no2.mapper.jackson
Class JacksonMapper
- java.lang.Object
-
- org.dizitart.no2.mapper.jackson.JacksonMapper
-
- All Implemented Interfaces:
AutoCloseable,NitriteMapper,NitritePlugin
public class JacksonMapper extends Object implements NitriteMapper
ANitriteMapperimplementation that uses Jackson ObjectMapper to convert objects to and from Nitrite document.- Since:
- 4.0
- Author:
- Anindya Chatterjee
- See Also:
NitriteMapper
-
-
Constructor Summary
Constructors Constructor Description JacksonMapper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidinitialize(NitriteConfig nitriteConfig)voidregisterJacksonModule(com.fasterxml.jackson.databind.Module module)Registers a Jackson module with the object mapper.<Source,Target>
ObjecttryConvert(Source source, Class<Target> type)Tries to convert the given source object to the target type using Jackson ObjectMapper.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.dizitart.no2.common.module.NitritePlugin
close
-
-
-
-
Method Detail
-
registerJacksonModule
public void registerJacksonModule(com.fasterxml.jackson.databind.Module module)
Registers a Jackson module with the object mapper.- Parameters:
module- the Jackson module to register- Throws:
ValidationException- if the module is null
-
tryConvert
public <Source,Target> Object tryConvert(Source source, Class<Target> type)
Tries to convert the given source object to the target type using Jackson ObjectMapper.If the source object is null, returns null. If the source object is a value node, returns the node value. If the target type is Document, converts the source object to a Document. If the source object is already a Document, converts it to the target type. If the conversion fails, throws an ObjectMappingException.
- Specified by:
tryConvertin interfaceNitriteMapper- Type Parameters:
Source- the type of the source objectTarget- the type of the target object- Parameters:
source- the source object to converttype- the target type to convert to- Returns:
- the converted object of the target type
- Throws:
ObjectMappingException- if the conversion fails
-
initialize
public void initialize(NitriteConfig nitriteConfig)
- Specified by:
initializein interfaceNitritePlugin
-
-