Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DataBinder, based on the DD4T 2 Java pattern, to get other types of pages from SDL
public interface CustomDataBinder {
<T extends Sitemap> T buildSitemap(String source, final Class<T> aClass) throws SerializationException;
}
public class CustomDataBinderImpl implements CustomDataBinder {
private static final Logger LOG = LoggerFactory.getLogger(CustomDataBinderImpl.class);
private static final ObjectMapper GENERIC_MAPPER = new ObjectMapper();
static {
GENERIC_MAPPER.configure(MapperFeature.IGNORE_DUPLICATE_MODULE_REGISTRATIONS,true);
GENERIC_MAPPER.registerModule(new JodaModule());
GENERIC_MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
private static final CustomDataBinderImpl INSTANCE = new CustomDataBinderImpl();
private CustomDataBinderImpl () {
LOG.info("CustomDataBinderImpl init.");
}
public static CustomDataBinderImpl getInstance () {
if (null == INSTANCE) {
LOG.error("DataBinderImpl not properly instantiated!");
}
return INSTANCE;
}
@Override
public <T extends Sitemap> T buildSitemap(String source, final Class<T> aClass) throws SerializationException {
try {
return GENERIC_MAPPER.readValue(source, aClass);
} catch (IOException e) {
LOG.error(DataBindConstants.MESSAGE_ERROR_DESERIALIZING, e);
throw new SerializationException(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.