@Override public SerializerFactory withConfig(Config config) { /* 22-Nov-2010, tatu: As with BeanSerializerFactory, must ensure type won't change * with this method, so: */ if (getClass() != CustomSerializerFactory.class) { throw new IllegalStateException("Subtype of CustomSerializerFactory ("+getClass().getName() +") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with " +"additional serializer definitions"); } return new CustomSerializerFactory(config); }
@Override public SerializerFactory withConfig(Config config) { /* 22-Nov-2010, tatu: As with BeanSerializerFactory, must ensure type won't change * with this method, so: */ if (getClass() != CustomSerializerFactory.class) { throw new IllegalStateException("Subtype of CustomSerializerFactory ("+getClass().getName() +") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with " +"additional serializer definitions"); } return new CustomSerializerFactory(config); }
@Override public SerializerFactory withConfig(Config config) { /* 22-Nov-2010, tatu: As with BeanSerializerFactory, must ensure type won't change * with this method, so: */ if (getClass() != CustomSerializerFactory.class) { throw new IllegalStateException("Subtype of CustomSerializerFactory ("+getClass().getName() +") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with " +"additional serializer definitions"); } return new CustomSerializerFactory(config); }
@Override public SerializerFactory withConfig(Config config) { /* 22-Nov-2010, tatu: As with BeanSerializerFactory, must ensure type won't change * with this method, so: */ if (getClass() != CustomSerializerFactory.class) { throw new IllegalStateException("Subtype of CustomSerializerFactory ("+getClass().getName() +") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with " +"additional serializer definitions"); } return new CustomSerializerFactory(config); }
@Override public SerializerFactory withConfig(Config config) { /* 22-Nov-2010, tatu: As with BeanSerializerFactory, must ensure type won't change * with this method, so: */ if (getClass() != CustomSerializerFactory.class) { throw new IllegalStateException("Subtype of CustomSerializerFactory ("+getClass().getName() +") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with " +"additional serializer definitions"); } return new CustomSerializerFactory(config); }
public class CustomObjectMapper extends ObjectMapper { public CustomObjectMapper() { CustomSerializerFactory sf = new CustomSerializerFactory(); sf.addSpecificMapping(ObjectId.class, new ObjectIdSerializer()); this.setSerializerFactory(sf); } }
/** * Associates all maps with our custom serialization mechanism, which will transform them into arrays of arrays * @see MapAsArraySerializer * @return */ @Produces public SerializerFactory createSerializerFactory() { CustomSerializerFactory customized = new CustomSerializerFactory(); customized.addGenericMapping(Map.class, new MapAsArraySerializer()); return customized; } public @Produces ObjectMapper createMapper() { ObjectMapper jsonMapper = new ObjectMapper(); // .... // now configure serializer jsonMapper.setSerializerFactory(createSerializerFactory()); // .... return jsonMapper; }
public void afterPropertiesSet() throws Exception { Assert.notNull(conversionService, "Must specify a valid ConversionService."); List<HttpMessageConverter<?>> converters = getRestTemplate().getMessageConverters(); ObjectMapper mapper = new ObjectMapper(); CustomSerializerFactory fac = new CustomSerializerFactory(); if (groovyPresent) { // Native conversion for Groovy GString objects fac.addSpecificMapping(GStringImpl.class, ToStringSerializer.instance); } mapper.setSerializerFactory(fac); for (HttpMessageConverter converter : converters) { if (converter instanceof MappingJacksonHttpMessageConverter) { ((MappingJacksonHttpMessageConverter) converter).setObjectMapper( mapper); } } }
XmlJavaTypeAdapters adapters = pkg.getAnnotation(XmlJavaTypeAdapters.class); if (adapters != null) { CustomSerializerFactory serializerFactory = new CustomSerializerFactory(); BeanDeserializerFactory deserializerFactory = new BeanDeserializerFactory(null); for (XmlJavaTypeAdapter a : adapters.value()) {