From 340913b16ffeee29c43e52e8cbf612570443b059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Fri, 18 Oct 2024 14:50:44 +0200 Subject: [PATCH 1/2] fix: Update code --- .../jsonb/type/JsonAttributeValueBinaryType.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/jsonb/type/JsonAttributeValueBinaryType.java b/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/jsonb/type/JsonAttributeValueBinaryType.java index 84cf1f5b6eaf..25031fbe0043 100644 --- a/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/jsonb/type/JsonAttributeValueBinaryType.java +++ b/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/jsonb/type/JsonAttributeValueBinaryType.java @@ -58,16 +58,18 @@ public String convertObjectToJson(Object object) { Map attrValueMap = new HashMap<>(); for (AttributeValue attributeValue : attributeValues) { - if (attributeValue.getAttribute() != null) { - attributeValue.setAttribute(new Attribute(attributeValue.getAttribute().getUid())); - attrValueMap.put(attributeValue.getAttribute().getUid(), attributeValue); + if (attributeValue.getAttribute() != null + && attributeValue.getAttribute().getUid() != null) { + String uid = attributeValue.getAttribute().getUid(); + attributeValue.setAttribute(new Attribute(uid)); + attrValueMap.put(uid, attributeValue); } } return writer.writeValueAsString(attrValueMap); - } catch (IOException e) { - throw new RuntimeException(e); + } catch (IOException ex) { + throw new RuntimeException("Failed to serialize JSON", ex); } } @@ -83,8 +85,8 @@ public Object convertJsonToObject(String content) { Map data = reader.readValue(content); return convertAttributeValueMapIntoSet(data); - } catch (IOException e) { - throw new RuntimeException(e); + } catch (IOException ex) { + throw new RuntimeException("Failed to deserialize JSON", ex); } } From 84618bb74966a83a0fb7f2a4f36125c03d465f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Fri, 18 Oct 2024 15:01:48 +0200 Subject: [PATCH 2/2] fix: Update code --- .../hibernate/jsonb/type/JsonAttributeValueBinaryType.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/jsonb/type/JsonAttributeValueBinaryType.java b/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/jsonb/type/JsonAttributeValueBinaryType.java index 25031fbe0043..2df4fdc0eceb 100644 --- a/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/jsonb/type/JsonAttributeValueBinaryType.java +++ b/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/jsonb/type/JsonAttributeValueBinaryType.java @@ -30,6 +30,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -69,7 +70,7 @@ public String convertObjectToJson(Object object) { return writer.writeValueAsString(attrValueMap); } catch (IOException ex) { - throw new RuntimeException("Failed to serialize JSON", ex); + throw new UncheckedIOException("Failed to serialize JSON", ex); } } @@ -86,7 +87,7 @@ public Object convertJsonToObject(String content) { return convertAttributeValueMapIntoSet(data); } catch (IOException ex) { - throw new RuntimeException("Failed to deserialize JSON", ex); + throw new UncheckedIOException("Failed to deserialize JSON", ex); } }