package io.openex.database.converter;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.openex.database.model.StatusReporting;

import javax.annotation.Resource;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.io.IOException;

@Converter(autoApply = true)
public class StatusReportingConverter implements AttributeConverter<StatusReporting, String> {

    @Resource
    private ObjectMapper mapper;

    @Override
    public String convertToDatabaseColumn(StatusReporting meta) {
        try {
            return mapper.writeValueAsString(meta);
        } catch (JsonProcessingException ex) {
            return null;
            // or throw an error
        }
    }

    @Override
    public StatusReporting convertToEntityAttribute(String dbData) {
        try {
            return mapper.readValue(dbData, StatusReporting.class);
        } catch (IOException ex) {
            // logger.error("Unexpected IOEx decoding json from database: " + dbData);
            return null;
        }
    }

}
@@ -857,24 +857,89 @@
 g dbData) %7B%0A
+        if (dbData == null) %7B%0A            return null;%0A        %7D%0A
         try 

Handle null reporting status