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

com.bazaarvoice.ostrich.JsonHelper Maven / Gradle / Ivy

package com.bazaarvoice.ostrich;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.MappingJsonFactory;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

class JsonHelper {
    private static final ObjectMapper JSON = new MappingJsonFactory()
            .getCodec()
            .configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);

    static String toJson(Object value) {
        try {
            return JSON.writeValueAsString(value);
        } catch (IOException e) {
            throw new AssertionError(e);  // Shouldn't get IO errors reading from a string
        }
    }

    static  T fromJson(String string, Class type) {
        try {
            return JSON.readValue(string, type);
        } catch (IOException e) {
            throw new AssertionError(e);  // Shouldn't get IO errors reading from a string
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy