Permalink
Browse files

Add support for deserializing HostAndPort.

  • Loading branch information...
1 parent f9cd302 commit d0c9c8f0c12a62d7852f08fad1288a3fbb94d254 @codahale codahale committed Apr 3, 2012
Showing with 15 additions and 0 deletions.
  1. +15 −0 dropwizard-core/src/main/java/com/yammer/dropwizard/json/GuavaExtrasModule.java
View
15 dropwizard-core/src/main/java/com/yammer/dropwizard/json/GuavaExtrasModule.java
@@ -1,6 +1,7 @@
package com.yammer.dropwizard.json;
import com.google.common.cache.CacheBuilderSpec;
+import com.google.common.net.HostAndPort;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.Version;
import org.codehaus.jackson.map.*;
@@ -11,6 +12,15 @@
public class GuavaExtrasModule extends Module {
@JsonCachable
+ private static class HostAndPortDeserializer extends JsonDeserializer<HostAndPort> {
+ @Override
+ public HostAndPort deserialize(JsonParser jp,
+ DeserializationContext ctxt) throws IOException {
+ return HostAndPort.fromString(jp.getText());
+ }
+ }
+
+ @JsonCachable
private static class CacheBuilderSpecDeserializer extends JsonDeserializer<CacheBuilderSpec> {
@Override
public CacheBuilderSpec deserialize(JsonParser jp,
@@ -33,6 +43,11 @@ public CacheBuilderSpec deserialize(JsonParser jp,
if (CacheBuilderSpec.class.isAssignableFrom(type.getRawClass())) {
return new CacheBuilderSpecDeserializer();
}
+
+ if (HostAndPort.class.isAssignableFrom(type.getRawClass())) {
+ return new HostAndPortDeserializer();
+ }
+
return super.findBeanDeserializer(type, config, provider, beanDesc, property);
}
}

0 comments on commit d0c9c8f

Please sign in to comment.