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

io.redskap.swagger.brake.report.json.JsonConverter Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package io.redskap.swagger.brake.report.json;

import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class JsonConverter {
    private final ObjectMapper objectMapper;

    public String convert(Object obj) {
        try {
            return objectMapper.writeValueAsString(obj);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

    public Map toMap(Object obj) {
        return objectMapper.convertValue(obj, new TypeReference>() {});
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy