[JAVA-15469] (#12979)

Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com>
This commit is contained in:
panos-kakos 2022-11-06 17:13:51 +00:00 committed by GitHub
parent fefc0d88e0
commit 2495e6f101
2 changed files with 5 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import javax.persistence.Id;
import javax.persistence.Table;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@Entity
@ -74,7 +75,7 @@ public class Customer {
}
public void deserializeCustomerAttributes() throws IOException {
this.customerAttributes = objectMapper.readValue(customerAttributeJSON, Map.class);
this.customerAttributes = objectMapper.readValue(customerAttributeJSON, new TypeReference<Map<String, Object>>() {});
}
}

View File

@ -1,6 +1,7 @@
package com.baeldung.hibernate.persistjson;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.AttributeConverter;
@ -10,6 +11,7 @@ import org.slf4j.LoggerFactory;
import com.baeldung.hibernate.interceptors.CustomInterceptor;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class HashMapConverter implements AttributeConverter<Map<String, Object>, String> {
@ -36,7 +38,7 @@ public class HashMapConverter implements AttributeConverter<Map<String, Object>,
Map<String, Object> customerInfo = null;
try {
customerInfo = objectMapper.readValue(customerInfoJSON, Map.class);
customerInfo = objectMapper.readValue(customerInfoJSON, new TypeReference<HashMap<String, Object>>() {});
} catch (final IOException e) {
logger.error("JSON reading error", e);
}