31 lines
807 B
Java
31 lines
807 B
Java
package eu.eudat.migration.utils;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import javax.persistence.AttributeConverter;
|
|
import java.util.Map;
|
|
|
|
public class JsonTypeConverter implements AttributeConverter<Map<String, Object>, String> {
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
@Override
|
|
public String convertToDatabaseColumn(Map<String, Object> customerInfo) {
|
|
try {
|
|
return objectMapper.writeValueAsString(customerInfo);
|
|
} catch (Exception e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Map<String, Object> convertToEntityAttribute(String customerInfoJSON) {
|
|
try {
|
|
return objectMapper.readValue(customerInfoJSON, Map.class);
|
|
} catch (Exception e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
}
|