Class Jackson2ModuleForIBeans

  • All Implemented Interfaces:
    Versioned

    public class Jackson2ModuleForIBeans
    extends Module
    Jackson2 configuration 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:
    • 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);