Announcement Announcement Module
Collapse
No announcement yet.
Spring Data REST - registering a Jackson module for serialization Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data REST - registering a Jackson module for serialization

    I have a working project based on the Spring Data REST example project, and I'm trying to do custom serialization using a Jackson module based on the wiki page.

    Here's my Jackson module:

    Code:
    public class CustomModule extends SimpleModule {
        public static Logger logger = LoggerFactory.getLogger(CustomModule.class);
    
        public CustomModule() {
            super("CustomModule", new Version(1, 0, 0, null));
        }
    
        @Override
        public void setupModule(SetupContext context) {
            logger.debug("CustomModule.setupModule");
            SimpleSerializers simpleSerializers = new SimpleSerializers();
            simpleSerializers.addSerializer(new CustomDateTimeSerializer());
            context.addSerializers(simpleSerializers);
        }
    
    }
    The wiki page says:

    Any Module bean declared within the scope of your ApplicationContext will be picked up by the exporter and registered with its ObjectMapper.
    I'm still pretty new to Spring, so I might just be putting my module bean definition in the wrong place; currently it's in src/main/resources/META-INF/spring-data-rest/shared.xml, which is imported from repositories-export.xml:

    Code:
    <bean id="customModule" class="org.hierax.wpa.schema.mapping.CustomModule" />
    I don't see the log statement in setupModule, but I do see log output for other classes in the same package.

    I'm using Spring Data REST 1.0.0.RC2.

    Re-posted from StackOverflow.

  • #2
    I've updated to Spring Data REST 1.0.0.RELEASE with JavaConfig, and I got my custom serializer working with the addition of @Component on the custom module.

    Code:
    @Component
    public class CustomJacksonModule extends SimpleModule {
    	
    	public CustomJacksonModule() {
    		super("CustomJacksonModule", new Version(1, 0, 0, null));
    	}
    
    	@Override
    	public void setupModule(SetupContext context) {
    		SimpleSerializers simpleSerializers = new SimpleSerializers();
    		simpleSerializers.addSerializer (new CustomDateTimeSerializer());
    		context.addSerializers(simpleSerializers);
    	}
    
    }
    Last edited by halcyon22; Mar 10th, 2013, 11:24 PM. Reason: with solution

    Comment

    Working...
    X