Skip to content

Commit

Permalink
Fix API issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kamfosica committed Jul 21, 2022
1 parent 5348bca commit d419d4d
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.google.gson.Gson;
import org.cga.sctp.core.BaseComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.util.Collections;
import java.util.List;

@Converter
public class HouseholdJsonMemberDataConverter implements AttributeConverter<List<IndividualDetails>, String> {
public class HouseholdJsonMemberDataConverter extends BaseComponent implements AttributeConverter<List<IndividualDetails>, String> {

@Autowired
private Gson gson;
Expand All @@ -63,10 +66,13 @@ public HouseholdJsonMemberDataConverter() {

@Override
public List<IndividualDetails> convertToEntityAttribute(String dbData) {
try {
return List.of(objectMapper.readValue(dbData, IndividualDetails[].class));
} catch (Exception e) {
throw new RuntimeException(e);
if (StringUtils.hasText(dbData)) {
try {
return List.of(objectMapper.readValue(dbData, IndividualDetails[].class));
} catch (Exception e) {
LOG.error("error converting json", e);
}
}
return Collections.emptyList();
}
}

0 comments on commit d419d4d

Please sign in to comment.