public class Jackson2ModuleForIBeans extends Module
Module for IBean support. Needs to be
configured in a Jackson2 ObjectMappers 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:
Jackson2Support.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);
Module.SetupContext| Constructor and Description |
|---|
Jackson2ModuleForIBeans()
Creates a
Jackson2ModuleForIBeans without having a
IBeanFactory provided. |
Jackson2ModuleForIBeans(IBeanFactory iBeanFactory)
Creates a
Jackson2ModuleForIBeans for a given
IBeanFactory. |
| Modifier and Type | Method and Description |
|---|---|
String |
getModuleName()
Returns "Jackson2ModuleForIBeans" as name of the Jackson2
Module. |
void |
setupModule(Module.SetupContext context)
Registers a deserializer factory (
Deserializers) that supports
any Jackson2Support sub-interface. |
Version |
version()
Returns
Version.unknownVersion(). |
public Jackson2ModuleForIBeans()
Jackson2ModuleForIBeans without having a
IBeanFactory provided. In this case the deserializer will use
default factory in IBean when creating new IBeans.public Jackson2ModuleForIBeans(IBeanFactory iBeanFactory)
Jackson2ModuleForIBeans for a given
IBeanFactory. In this case the JSON deserializer will use the
provides factory in IBean when creating new IBeans.iBeanFactory - the factory used by the deserializer; if null the
deserializer will use the default factory in IBean for
IBean creation.public String getModuleName()
Module.getModuleName in class ModuleModule.getModuleName()public Version version()
Version.unknownVersion().version in interface Versionedversion in class ModuleModule.version()public void setupModule(Module.SetupContext context)
Deserializers) that supports
any Jackson2Support sub-interface.setupModule in class ModuleModule.setupModule(SetupContext)