Package org.coliper.ibean.extension
Class Jackson2ModuleForIBeans
- java.lang.Object
-
- com.fasterxml.jackson.databind.Module
-
- org.coliper.ibean.extension.Jackson2ModuleForIBeans
-
- All Implemented Interfaces:
Versioned
public class Jackson2ModuleForIBeans extends Module
Jackson2 configurationModule
for IBean support. Needs to be configured in a Jackson2ObjectMapper
s to enable JSON serialization and deserialization of IBeans. Three prerequisites need to be fulfilled so that an IBean can be converted to and from JSON with Jackson2:- Jackson2 version 2.6 or higher must be found on the classpath.
- IBean must implement extension interface
Jackson2Support
. - ObjectMapper used for convertion needs to have
Jackson2ModuleForIBeans
added to its configuration.
Following code snippets show an example usage:
IBeanFactory factory = ...; // Interface BeanType needs to extend Jackson2Support BeanType someBean = factory.create(BeanType.class); ... // Configure Jackson ObjectMapper ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new Jackson2ModuleForIBeans(factory)); // Serialize to JSON and back String json = mapper.writeValueAsString(someBean); BeanType deserializedBean = mapper.readValue(json, BeanType.class);
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.Module
Module.SetupContext
-
-
Constructor Summary
Constructors Constructor Description Jackson2ModuleForIBeans()
Creates aJackson2ModuleForIBeans
without having aIBeanFactory
provided.Jackson2ModuleForIBeans(IBeanFactory iBeanFactory)
Creates aJackson2ModuleForIBeans
for a givenIBeanFactory
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getModuleName()
Returns "Jackson2ModuleForIBeans" as name of the Jackson2Module
.void
setupModule(Module.SetupContext context)
Registers a deserializer factory (Deserializers
) that supports anyJackson2Support
sub-interface.Version
version()
ReturnsVersion.unknownVersion()
.
-
-
-
Constructor Detail
-
Jackson2ModuleForIBeans
public Jackson2ModuleForIBeans()
Creates aJackson2ModuleForIBeans
without having aIBeanFactory
provided. In this case the deserializer will use default factory inIBean
when creating new IBeans.
-
Jackson2ModuleForIBeans
public Jackson2ModuleForIBeans(IBeanFactory iBeanFactory)
Creates aJackson2ModuleForIBeans
for a givenIBeanFactory
. In this case the JSON deserializer will use the provides factory inIBean
when creating new IBeans.- Parameters:
iBeanFactory
- the factory used by the deserializer; ifnull
the deserializer will use the default factory inIBean
for IBean creation.
-
-
Method Detail
-
getModuleName
public String getModuleName()
Returns "Jackson2ModuleForIBeans" as name of the Jackson2Module
.- Specified by:
getModuleName
in classModule
- See Also:
Module.getModuleName()
-
version
public Version version()
ReturnsVersion.unknownVersion()
.- Specified by:
version
in interfaceVersioned
- Specified by:
version
in classModule
- See Also:
Module.version()
-
setupModule
public void setupModule(Module.SetupContext context)
Registers a deserializer factory (Deserializers
) that supports anyJackson2Support
sub-interface.- Specified by:
setupModule
in classModule
- See Also:
Module.setupModule(SetupContext)
-
-