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 configurationModulefor IBean support. Needs to be configured in a Jackson2ObjectMappers 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
Jackson2ModuleForIBeansadded 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 aJackson2ModuleForIBeanswithout having aIBeanFactoryprovided.Jackson2ModuleForIBeans(IBeanFactory iBeanFactory)Creates aJackson2ModuleForIBeansfor a givenIBeanFactory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetModuleName()Returns "Jackson2ModuleForIBeans" as name of the Jackson2Module.voidsetupModule(Module.SetupContext context)Registers a deserializer factory (Deserializers) that supports anyJackson2Supportsub-interface.Versionversion()ReturnsVersion.unknownVersion().
-
-
-
Constructor Detail
-
Jackson2ModuleForIBeans
public Jackson2ModuleForIBeans()
Creates aJackson2ModuleForIBeanswithout having aIBeanFactoryprovided. In this case the deserializer will use default factory inIBeanwhen creating new IBeans.
-
Jackson2ModuleForIBeans
public Jackson2ModuleForIBeans(IBeanFactory iBeanFactory)
Creates aJackson2ModuleForIBeansfor a givenIBeanFactory. In this case the JSON deserializer will use the provides factory inIBeanwhen creating new IBeans.- Parameters:
iBeanFactory- the factory used by the deserializer; ifnullthe deserializer will use the default factory inIBeanfor IBean creation.
-
-
Method Detail
-
getModuleName
public String getModuleName()
Returns "Jackson2ModuleForIBeans" as name of the Jackson2Module.- Specified by:
getModuleNamein classModule- See Also:
Module.getModuleName()
-
version
public Version version()
ReturnsVersion.unknownVersion().- Specified by:
versionin interfaceVersioned- Specified by:
versionin classModule- See Also:
Module.version()
-
setupModule
public void setupModule(Module.SetupContext context)
Registers a deserializer factory (Deserializers) that supports anyJackson2Supportsub-interface.- Specified by:
setupModulein classModule- See Also:
Module.setupModule(SetupContext)
-
-