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

com.tosan.tools.tracker.starter.model.TrackDataConverter Maven / Gradle / Ivy

The newest version!
package com.tosan.tools.tracker.starter.model;

import com.fasterxml.jackson.core.JsonProcessingException;
import jakarta.persistence.AttributeConverter;

import java.util.Map;

/**
 * @author M.khoshnevisan
 * @since 7/15/2023
 */
public class TrackDataConverter implements AttributeConverter, String> {

    @Override
    public String convertToDatabaseColumn(Map trackData) {
        if (trackData == null) {
            return null;
        }
        try {
            return TrackerStaticMapper.objectMapper.writeValueAsString(trackData);
        } catch (JsonProcessingException e) {
            throw new RuntimeException("invalid json: {}", e);
        }
    }

    @Override
    @SuppressWarnings("unchecked")
    public Map convertToEntityAttribute(String trackData) {
        if (trackData == null) {
            return null;
        }
        try {
            return TrackerStaticMapper.objectMapper.readValue(trackData, Map.class);
        } catch (JsonProcessingException e) {
            throw new RuntimeException("invalid json: {}", e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy