Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.clustermate.json;
 
 
public class ClusterMateTypesModule extends Module
    protected final boolean _cfgUseNumerics;
    public ClusterMateTypesModule(boolean useNumerics) {
    	 = useNumerics;
    }
    @Override
    public String getModuleName() {
        return "ClusterMateTypes";
    }
    @Override
    public Version version() {
        return Version.unknownVersion();
    }
    @Override
    public void setupModule(SetupContext context)
    {
        SimpleDeserializers desers = new SimpleDeserializers();
        SimpleSerializers sers = new SimpleSerializers();
        desers.addDeserializer(IpAndPort.classnew IpAndPortDeserializer());
        sers.addSerializer(IpAndPort.classnew IpAndPortSerializer());
        // for KeyRange, only manual serializer; deserializer with mix-ins
        sers.addSerializer(KeyRange.classnew KeyRangeSerializer());
        desers.addDeserializer(KeySpace.classnew KeySpaceDeserializer());
        sers.addSerializer(KeySpace.classnew KeySpaceSerializer());
        desers.addDeserializer(StorableKey.classnew StorableKeyDeserializer());
        sers.addSerializer(StorableKey.classnew StorableKeySerializer());
//        desers.addDeserializer(ClientId.class, new ClientIdDeserializer());
//        sers.addSerializer(ClientId.class, new ClientIdSerializer(_cfgUseNumerics));
        context.addDeserializers(desers);
        context.addSerializers(sers);
        // Plus mix-ins cover structured types:
        context.setMixInAnnotations(KeyRange.classKeyRangeMixins.class);
    }
    /*
    /**********************************************************************
    /* Helper types for mix-ins
    /**********************************************************************
     */

    
Instead of trying to write a manual deserializer for KeyRange, let's use mix-ins; this way no annotations are needed there, but things will work as if they were.
    abstract static class KeyRangeMixins extends KeyRange
    {
        @JsonCreator
        protected KeyRangeMixins(External ext) { super(ext); }
    }
New to GrepCode? Check out our FAQ X