UCROptionsConverter.java
package com.tradecloud.converter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tradecloud.domain.shipment.clearing.UCROptions;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
@Converter(autoApply = false)
public class UCROptionsConverter implements AttributeConverter<UCROptions, String> {
private static final ObjectMapper objectMapper = new ObjectMapper();
@Override
public String convertToDatabaseColumn(UCROptions attribute) {
if (attribute == null) return null;
try {
return objectMapper.writeValueAsString(attribute);
} catch (Exception e) {
throw new IllegalArgumentException("Error serializing UCROptions", e);
}
}
@Override
public UCROptions convertToEntityAttribute(String dbData) {
if (dbData == null || dbData.isBlank()) return null;
try {
return objectMapper.readValue(dbData, UCROptions.class);
} catch (Exception e) {
throw new IllegalArgumentException("Error deserializing UCROptions", e);
}
}
}