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

org.openl.rules.ruleservice.jaxrs.JacksonObjectSerializer Maven / Gradle / Ivy

There is a newer version: 5.27.9
Show newest version
package org.openl.rules.ruleservice.jaxrs;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.openl.rules.ruleservice.storelogdata.ObjectSerializer;
import org.openl.rules.ruleservice.storelogdata.ProcessingException;

public class JacksonObjectSerializer implements ObjectSerializer {

    private final ObjectMapper objectMapper;

    public JacksonObjectSerializer(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

    @Override
    public  T readValue(String content, Class type) throws ProcessingException {
        try {
            return objectMapper.readValue(content, type);
        } catch (JsonProcessingException e) {
            throw new ProcessingException(e);
        }
    }

    @Override
    public String writeValueAsString(Object obj) throws ProcessingException {
        if (obj instanceof String) {
            return (String) obj;
        }
        try {
            return objectMapper.writeValueAsString(obj);
        } catch (JsonProcessingException e) {
            throw new ProcessingException(e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy