Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.clustermate.client.util;
 
 import java.io.*;
 
 
{link ContentConverter} implementation that handles variations in two dimensions: in target type (one converter instance created per type), and in underlying data format (which is chosen dynamically)
public class GenericContentConverter<T> implements ContentConverter<T>
    protected final static SmileFactory SMILE_FACTORY = new SmileFactory();
    protected final ObjectReader _jsonReader;
    public GenericContentConverter(ObjectMapper jsonMapperClass<T> targetType) {
         = jsonMapper.reader(targetType);
    }
    public GenericContentConverter(ObjectMapper jsonMapperJavaType targetType) {
         = jsonMapper.reader(targetType);
    }
    
    @Override
    public T convert(ContentType contentTypeInputStream in)
        throws IOException
    {
        return _chooseReader(contentType).readValue(in);
    }
    @Override
    public T convert(ContentType contentTypebyte[] bufferint offset,
            int lengththrows IOException {
        return _chooseReader(contentType).readValue(bufferoffsetlength);
    }
    protected ObjectReader _chooseReader(ContentType contentType) {
        switch (contentType) {
        case // only special case is Smile
            return .with();
        case :
            return ;
        default:
        }
        // TEXT not supported..
        throw new IllegalArgumentException("Can not handle content type '"+contentType+"'");
    }
New to GrepCode? Check out our FAQ X