Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplify JsonEnvironment.

  • Loading branch information...
commit b9da347e24d8abb6271eea881077e70285aa8eaa 1 parent 03bc4d0
@codahale codahale authored
View
2  dropwizard-client/src/main/java/com/yammer/dropwizard/client/JerseyClientBuilder.java
@@ -177,7 +177,7 @@ public Client build() {
configuration.getMaxThreads(),
60,
TimeUnit.SECONDS),
- environment.getJsonEnvironment().buildObjectMapper());
+ environment.getJsonEnvironment().build());
}
private Client build(ExecutorService threadPool,
View
4 dropwizard-client/src/test/java/com/yammer/dropwizard/client/tests/JerseyClientBuilderTest.java
@@ -181,7 +181,7 @@ public void usesAnObjectMapperFromTheEnvironment() throws Exception {
60,
TimeUnit.SECONDS)).thenReturn(executorService);
- when(jsonEnvironment.buildObjectMapper()).thenReturn(objectMapper);
+ when(jsonEnvironment.build()).thenReturn(objectMapper);
final Client client = builder.using(environment).build();
@@ -209,7 +209,7 @@ public void usesAnExecutorServiceFromTheEnvironment() throws Exception {
60,
TimeUnit.SECONDS)).thenReturn(executorService);
- when(jsonEnvironment.buildObjectMapper()).thenReturn(objectMapper);
+ when(jsonEnvironment.build()).thenReturn(objectMapper);
final ApacheHttpClient4 client = (ApacheHttpClient4) builder.using(configuration)
.using(environment).build();
View
2  dropwizard-core/src/main/java/com/yammer/dropwizard/cli/ConfiguredCommand.java
@@ -51,7 +51,7 @@ public final void run(Bootstrap<?> bootstrap, Namespace namespace) throws Except
final T configuration = parseConfiguration(bootstrap.getConfigurationProvider(),
namespace.getString("file"),
getConfigurationClass(),
- bootstrap.getObjectMapperFactory().copy());
+ new ObjectMapperFactory(bootstrap.getObjectMapperFactory()));
if (configuration != null) {
new LoggingFactory(configuration.getLoggingConfiguration(),
bootstrap.getName()).configure();
View
3  dropwizard-core/src/main/java/com/yammer/dropwizard/cli/EnvironmentCommand.java
@@ -4,6 +4,7 @@
import com.yammer.dropwizard.config.Bootstrap;
import com.yammer.dropwizard.config.Configuration;
import com.yammer.dropwizard.config.Environment;
+import com.yammer.dropwizard.json.ObjectMapperFactory;
import com.yammer.dropwizard.validation.Validator;
import net.sourceforge.argparse4j.inf.Namespace;
@@ -31,7 +32,7 @@ protected EnvironmentCommand(Service<T> service, String name, String description
@Override
protected final void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception {
final Environment environment = new Environment(bootstrap.getName(),
- bootstrap.getObjectMapperFactory().copy(),
+ new ObjectMapperFactory(bootstrap.getObjectMapperFactory()),
new Validator());
bootstrap.runWithBundles(configuration, environment);
service.run(configuration, environment);
View
7 dropwizard-core/src/main/java/com/yammer/dropwizard/config/Environment.java
@@ -1,6 +1,5 @@
package com.yammer.dropwizard.config;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.sun.jersey.spi.container.servlet.ServletContainer;
@@ -49,7 +48,7 @@ public Environment(String name,
ObjectMapperFactory objectMapperFactory,
Validator validator) {
this.name = name;
- this.jsonEnvironment = new JsonEnvironment(objectMapperFactory.copy());
+ this.jsonEnvironment = new JsonEnvironment(objectMapperFactory);
this.validator = validator;
final DropwizardResourceConfig jerseyConfig = new DropwizardResourceConfig(false);
@@ -124,8 +123,4 @@ Server getServer() {
ServletContextHandler getAdminContext() {
return adminContext;
}
-
- ObjectMapper buildObjectMapper() {
- return jsonEnvironment.buildObjectMapper();
- }
}
View
3  dropwizard-core/src/main/java/com/yammer/dropwizard/config/ServerFactory.java
@@ -349,7 +349,8 @@ private Handler createExternalServlet(Environment env) {
final ServletContainer jerseyContainer = env.getJerseyServletContainer();
if (jerseyContainer != null) {
env.getJerseyEnvironment().addProvider(
- new JacksonMessageBodyProvider(env.buildObjectMapper(), env.getValidator())
+ new JacksonMessageBodyProvider(env.getJsonEnvironment().build(),
+ env.getValidator())
);
final ServletHolder jerseyHolder = new ServletHolder(jerseyContainer);
jerseyHolder.setInitOrder(Integer.MAX_VALUE);
View
71 dropwizard-core/src/main/java/com/yammer/dropwizard/json/ObjectMapperFactory.java
@@ -93,6 +93,40 @@ public ObjectMapperFactory() {
registerModule(new JodaModule());
}
+ /**
+ * Creates a new {@link ObjectMapperFactory} with the same properties as another.
+ *
+ * @param other another {@link ObjectMapperFactory}
+ */
+ public ObjectMapperFactory(ObjectMapperFactory other) {
+ this.modules = Lists.newArrayList(other.modules);
+
+ this.mapperFeatures = Maps.newHashMap(other.mapperFeatures);
+ this.deserializationFeatures = Maps.newHashMap(other.deserializationFeatures);
+ this.serializationFeatures = Maps.newHashMap(other.serializationFeatures);
+ this.generatorFeatures = Maps.newHashMap(other.generatorFeatures);
+ this.parserFeatures = Maps.newHashMap(other.parserFeatures);
+ this.factoryFeatures = Maps.newHashMap(other.factoryFeatures);
+ this.visibilityRules = Maps.newHashMap(other.visibilityRules);
+
+ this.annotationIntrospector = other.annotationIntrospector;
+ this.dateFormat = other.dateFormat;
+ this.defaultTyping = other.defaultTyping;
+ this.filters = other.filters;
+ this.handlerInstantiator = other.handlerInstantiator;
+ this.injectableValues = other.injectableValues;
+ this.locale = other.locale;
+ this.mixinAnnotations = other.mixinAnnotations;
+ this.nodeFactory = other.nodeFactory;
+ this.propertyNamingStrategy = other.propertyNamingStrategy;
+ this.serializationInclusion = other.serializationInclusion;
+ this.serializerFactory = other.serializerFactory;
+ this.serializerProvider = other.serializerProvider;
+ this.subtypeResolver = other.subtypeResolver;
+ this.timeZone = other.timeZone;
+ this.visibilityChecker = other.visibilityChecker;
+ }
+
public AnnotationIntrospector getAnnotationIntrospector() {
return annotationIntrospector;
}
@@ -612,41 +646,4 @@ public ObjectMapper configure(ObjectMapper mapper) {
return mapper;
}
-
- /**
- * Creates a copy of {@code this}.
- *
- * @return a copy of {@code this}
- */
- public ObjectMapperFactory copy() {
- final ObjectMapperFactory factory = new ObjectMapperFactory();
-
- factory.modules.addAll(modules);
- factory.mapperFeatures.putAll(mapperFeatures);
- factory.deserializationFeatures.putAll(deserializationFeatures);
- factory.serializationFeatures.putAll(serializationFeatures);
- factory.generatorFeatures.putAll(generatorFeatures);
- factory.parserFeatures.putAll(parserFeatures);
- factory.factoryFeatures.putAll(factoryFeatures);
- factory.visibilityRules.putAll(visibilityRules);
-
- factory.annotationIntrospector = annotationIntrospector;
- factory.dateFormat = dateFormat;
- factory.defaultTyping = defaultTyping;
- factory.filters = filters;
- factory.handlerInstantiator = handlerInstantiator;
- factory.injectableValues = injectableValues;
- factory.locale = locale;
- factory.mixinAnnotations = mixinAnnotations;
- factory.nodeFactory = nodeFactory;
- factory.propertyNamingStrategy = propertyNamingStrategy;
- factory.serializationInclusion = serializationInclusion;
- factory.serializerFactory = serializerFactory;
- factory.serializerProvider = serializerProvider;
- factory.subtypeResolver = subtypeResolver;
- factory.timeZone = timeZone;
- factory.visibilityChecker = visibilityChecker;
-
- return factory;
- }
}
View
253 dropwizard-core/src/main/java/com/yammer/dropwizard/setup/JsonEnvironment.java
@@ -1,256 +1,9 @@
package com.yammer.dropwizard.setup;
-import com.fasterxml.jackson.annotation.JsonAutoDetect;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.PropertyAccessor;
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.*;
-import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
-import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
-import com.fasterxml.jackson.databind.jsontype.SubtypeResolver;
-import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
-import com.fasterxml.jackson.databind.ser.FilterProvider;
-import com.fasterxml.jackson.databind.ser.SerializerFactory;
-import com.fasterxml.jackson.databind.type.TypeFactory;
import com.yammer.dropwizard.json.ObjectMapperFactory;
-import java.text.DateFormat;
-import java.util.Locale;
-import java.util.Map;
-import java.util.TimeZone;
-
-public class JsonEnvironment {
- private final ObjectMapperFactory objectMapperFactory;
-
- public JsonEnvironment(ObjectMapperFactory objectMapperFactory) {
- this.objectMapperFactory = objectMapperFactory;
- }
-
- public AnnotationIntrospector getAnnotationIntrospector() {
- return objectMapperFactory.getAnnotationIntrospector();
- }
-
- public void enable(JsonFactory.Feature... features) {
- objectMapperFactory.enable(features);
- }
-
- public void setHandlerInstantiator(HandlerInstantiator handlerInstantiator) {
- objectMapperFactory.setHandlerInstantiator(handlerInstantiator);
- }
-
- public void setAnnotationIntrospector(AnnotationIntrospector annotationIntrospector) {
- objectMapperFactory.setAnnotationIntrospector(annotationIntrospector);
- }
-
- public boolean isEnabled(DeserializationFeature feature) {
- return objectMapperFactory.isEnabled(feature);
- }
-
- public void disable(DeserializationFeature... features) {
- objectMapperFactory.disable(features);
- }
-
- public void enable(JsonGenerator.Feature... features) {
- objectMapperFactory.enable(features);
- }
-
- public void setMixinAnnotations(Map<Class<?>, Class<?>> mixinAnnotations) {
- objectMapperFactory.setMixinAnnotations(mixinAnnotations);
- }
-
- public FilterProvider getFilters() {
- return objectMapperFactory.getFilters();
- }
-
- public void disable(JsonGenerator.Feature... features) {
- objectMapperFactory.disable(features);
- }
-
- public VisibilityChecker<?> getVisibilityChecker() {
- return objectMapperFactory.getVisibilityChecker();
- }
-
- public Map<Class<?>, Class<?>> getMixinAnnotations() {
- return objectMapperFactory.getMixinAnnotations();
- }
-
- public JsonInclude.Include getSerializationInclusion() {
- return objectMapperFactory.getSerializationInclusion();
- }
-
- public void setInjectableValues(InjectableValues injectableValues) {
- objectMapperFactory.setInjectableValues(injectableValues);
- }
-
- public TypeResolverBuilder<?> getDefaultTyping() {
- return objectMapperFactory.getDefaultTyping();
- }
-
- public void disable(MapperFeature... features) {
- objectMapperFactory.disable(features);
- }
-
- public void setDateFormat(DateFormat dateFormat) {
- objectMapperFactory.setDateFormat(dateFormat);
- }
-
- public void setVisibilityRules(PropertyAccessor accessor, JsonAutoDetect.Visibility visibility) {
- objectMapperFactory.setVisibilityRules(accessor, visibility);
- }
-
- public void setNodeFactory(JsonNodeFactory nodeFactory) {
- objectMapperFactory.setNodeFactory(nodeFactory);
- }
-
- public void setDefaultTyping(TypeResolverBuilder<?> defaultTyping) {
- objectMapperFactory.setDefaultTyping(defaultTyping);
- }
-
- public boolean isEnabled(JsonFactory.Feature feature) {
- return objectMapperFactory.isEnabled(feature);
- }
-
- public PropertyNamingStrategy getPropertyNamingStrategy() {
- return objectMapperFactory.getPropertyNamingStrategy();
- }
-
- public void setSerializerProvider(DefaultSerializerProvider serializerProvider) {
- objectMapperFactory.setSerializerProvider(serializerProvider);
- }
-
- public SubtypeResolver getSubtypeResolver() {
- return objectMapperFactory.getSubtypeResolver();
- }
-
- public DefaultSerializerProvider getSerializerProvider() {
- return objectMapperFactory.getSerializerProvider();
- }
-
- public void registerModule(Module module) {
- objectMapperFactory.registerModule(module);
- }
-
- public boolean isEnabled(JsonGenerator.Feature feature) {
- return objectMapperFactory.isEnabled(feature);
- }
-
- public void setTypeFactory(TypeFactory typeFactory) {
- objectMapperFactory.setTypeFactory(typeFactory);
- }
-
- public void setFilters(FilterProvider filters) {
- objectMapperFactory.setFilters(filters);
- }
-
- public void setVisibilityChecker(VisibilityChecker<?> visibilityChecker) {
- objectMapperFactory.setVisibilityChecker(visibilityChecker);
- }
-
- public boolean isEnabled(SerializationFeature feature) {
- return objectMapperFactory.isEnabled(feature);
- }
-
- public boolean isEnabled(JsonParser.Feature feature) {
- return objectMapperFactory.isEnabled(feature);
- }
-
- public void enable(MapperFeature... features) {
- objectMapperFactory.enable(features);
- }
-
- public boolean isEnabled(MapperFeature feature) {
- return objectMapperFactory.isEnabled(feature);
- }
-
- public HandlerInstantiator getHandlerInstantiator() {
- return objectMapperFactory.getHandlerInstantiator();
- }
-
- public void enable(SerializationFeature... features) {
- objectMapperFactory.enable(features);
- }
-
- public JsonAutoDetect.Visibility getVisibility(PropertyAccessor accessor) {
- return objectMapperFactory.getVisibility(accessor);
- }
-
- public InjectableValues getInjectableValues() {
- return objectMapperFactory.getInjectableValues();
- }
-
- public void disable(SerializationFeature... features) {
- objectMapperFactory.disable(features);
- }
-
- public Locale getLocale() {
- return objectMapperFactory.getLocale();
- }
-
- public void setSubtypeResolver(SubtypeResolver subtypeResolver) {
- objectMapperFactory.setSubtypeResolver(subtypeResolver);
- }
-
- public void setLocale(Locale locale) {
- objectMapperFactory.setLocale(locale);
- }
-
- public void disable(JsonParser.Feature... features) {
- objectMapperFactory.disable(features);
- }
-
- public DateFormat getDateFormat() {
- return objectMapperFactory.getDateFormat();
- }
-
- public TypeFactory getTypeFactory() {
- return objectMapperFactory.getTypeFactory();
- }
-
- public JsonNodeFactory getNodeFactory() {
- return objectMapperFactory.getNodeFactory();
- }
-
- public void setTimeZone(TimeZone timeZone) {
- objectMapperFactory.setTimeZone(timeZone);
- }
-
- public void setSerializerFactory(SerializerFactory serializerFactory) {
- objectMapperFactory.setSerializerFactory(serializerFactory);
- }
-
- public void enable(JsonParser.Feature... features) {
- objectMapperFactory.enable(features);
- }
-
- public TimeZone getTimeZone() {
- return objectMapperFactory.getTimeZone();
- }
-
- public void setSerializationInclusion(JsonInclude.Include serializationInclusion) {
- objectMapperFactory.setSerializationInclusion(serializationInclusion);
- }
-
- public void setPropertyNamingStrategy(PropertyNamingStrategy propertyNamingStrategy) {
- objectMapperFactory.setPropertyNamingStrategy(propertyNamingStrategy);
- }
-
- public void disable(JsonFactory.Feature... features) {
- objectMapperFactory.disable(features);
- }
-
- public void enable(DeserializationFeature... features) {
- objectMapperFactory.enable(features);
- }
-
- public SerializerFactory getSerializerFactory() {
- return objectMapperFactory.getSerializerFactory();
- }
-
- public ObjectMapper buildObjectMapper() {
- return objectMapperFactory.build();
+public class JsonEnvironment extends ObjectMapperFactory {
+ public JsonEnvironment(ObjectMapperFactory factory) {
+ super(factory);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.