This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects

Resolve "ElementCollection aus AuditLogEvent entfernen"

All threads resolved!
Compare and
4 files
+ 63
8
Compare changes
  • Side-by-side
  • Inline
Files
4
package at.ac.uibk.gitsearch.domain.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import org.apache.tika.utils.StringUtils;
@Converter
@SuppressWarnings({ "PMD.AvoidThrowingRawExceptionTypes", "PMD.AvoidCatchingGenericException" })
public class MapToJsonConverter implements AttributeConverter<Map<String, String>, String> {
private final ObjectMapper objectMapper = new ObjectMapper();
@Override
public String convertToDatabaseColumn(Map<String, String> attribute) {
if (attribute == null) {
return null;
}
try {
return objectMapper.writeValueAsString(attribute);
} catch (JsonProcessingException e) {
throw new RuntimeException("Error saving map to Json", e);
}
}
@Override
public Map<String, String> convertToEntityAttribute(String dbData) {
if (StringUtils.isEmpty(dbData)) {
return new ConcurrentHashMap<>();
}
try {
return objectMapper.readValue(dbData, Map.class);
} catch (Exception e) {
throw new RuntimeException("Error converting JSON to map", e);
}
}
}