From 2495e6f1016f9145c250606405c7da2eec1d273d Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Sun, 6 Nov 2022 17:13:51 +0000 Subject: [PATCH] [JAVA-15469] (#12979) Co-authored-by: panagiotiskakos --- .../java/com/baeldung/hibernate/persistjson/Customer.java | 3 ++- .../com/baeldung/hibernate/persistjson/HashMapConverter.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/persistjson/Customer.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/persistjson/Customer.java index 6bd1c24869..3e214d58f9 100644 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/persistjson/Customer.java +++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/persistjson/Customer.java @@ -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>() {}); } } diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/persistjson/HashMapConverter.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/persistjson/HashMapConverter.java index b1c2d50480..5f3482b36f 100644 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/persistjson/HashMapConverter.java +++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/persistjson/HashMapConverter.java @@ -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, String> { @@ -36,7 +38,7 @@ public class HashMapConverter implements AttributeConverter, Map customerInfo = null; try { - customerInfo = objectMapper.readValue(customerInfoJSON, Map.class); + customerInfo = objectMapper.readValue(customerInfoJSON, new TypeReference>() {}); } catch (final IOException e) { logger.error("JSON reading error", e); }