Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.yammer.dropwizard.json;
 
 
public class GuavaExtrasModule extends Module {
    private static class HostAndPortDeserializer extends JsonDeserializer<HostAndPort> {
        @Override
        public HostAndPort deserialize(JsonParser jp,
                                       DeserializationContext ctxtthrows IOException {
            return HostAndPort.fromString(jp.getText());
        }
    }
    private static class CacheBuilderSpecDeserializer extends JsonDeserializer<CacheBuilderSpec> {
        @Override
        public CacheBuilderSpec deserialize(JsonParser jp,
                                            DeserializationContext ctxtthrows IOException {
            final String text = jp.getText();
            if ("off".equalsIgnoreCase(text) || "disabled".equalsIgnoreCase(text)) {
                return CacheBuilderSpec.disableCaching();
            }
            return CacheBuilderSpec.parse(text);
        }
    }
    private static class GuavaExtrasDeserializers extends Deserializers.Base {
        @Override
        public JsonDeserializer<?> findBeanDeserializer(JavaType type,
                                                        DeserializationConfig config,
                                                        BeanDescription beanDescthrows JsonMappingException {
            if (CacheBuilderSpec.class.isAssignableFrom(type.getRawClass())) {
                return new CacheBuilderSpecDeserializer();
            }
            if (HostAndPort.class.isAssignableFrom(type.getRawClass())) {
                return new HostAndPortDeserializer();
            }
            return super.findBeanDeserializer(typeconfigbeanDesc);
        }
    }
    @Override
    public String getModuleName() {
        return "guava-extras";
    }
    @Override
    public Version version() {
        return Version.unknownVersion();
    }
    @Override
    public void setupModule(SetupContext context) {
        context.addDeserializers(new GuavaExtrasDeserializers());
    }
New to GrepCode? Check out our FAQ X