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

ie.curiositysoftware.utils.UnirestHelper Maven / Gradle / Ivy

There is a newer version: 2.0.67
Show newest version
package ie.curiositysoftware.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import kong.unirest.ObjectMapper;
import kong.unirest.Unirest;

import java.io.IOException;

public class UnirestHelper {
    public static void initUnirestMapper()
    {
        ObjectMapper om = (new ObjectMapper() {
            public com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
            {
                jacksonObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            }

            public  T readValue(String value, Class valueType) {
                try {
                    return jacksonObjectMapper.readValue(value, valueType);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            public String writeValue(Object value) {
                try {
                    return jacksonObjectMapper.writeValueAsString(value);
                } catch (JsonProcessingException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        Unirest.config().setObjectMapper(om);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy