All Downloads are FREE. Search and download functionalities are using the official Maven repository.

restx.converters.MainStringConverter Maven / Gradle / Ivy

There is a newer version: 1.2.0-rc2
Show newest version
package restx.converters;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Optional;
import restx.factory.Component;
import restx.jackson.FrontObjectMapperFactory;

import javax.inject.Named;

/**
 * User: xavierhanin
 * Date: 2/5/13
 * Time: 11:18 PM
 */
@Component
public class MainStringConverter {
    private final ObjectMapper mapper;

    public MainStringConverter(@Named(FrontObjectMapperFactory.MAPPER_NAME) ObjectMapper mapper) {
        this.mapper = mapper;
    }

    public  Optional convert(Optional value, Class toClass) {
        if(value.isPresent()){
            return Optional.of(convert(value.get(), toClass));
        } else {
            return Optional.absent();
        }
    }

    public boolean canDeserialize(JavaType javaType) {
        return mapper.canDeserialize(javaType);
    }

    public  T convert(String value, Class toClass) {
        return mapper.convertValue(value, toClass);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy