/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023-2024 Nordix Foundation.
+ * Copyright (C) 2023-2024,2026 OpenInfra Foundation Europe. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageUtils.assertSerializable;
+import static org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageUtils.assertSerializeBehaviour;
import static org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageUtils.removeVariableFields;
import java.time.Instant;
+import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
property.setType("testType");
var standardCoder = new StandardCoder();
var json = standardCoder.encode(property);
- var propertiesMap = Map.of("Prop1", (Object) json);
+ var propertiesMap = new HashMap<String, Object>();
+ propertiesMap.put("Prop1", json);
+ propertiesMap.put("testProperty", "dummy");
+ propertiesMap.put("nullProperty", null);
acElement.setProperties(propertiesMap);
var participantDeploy = new ParticipantDeploy();
assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
assertSerializable(orig, AutomationCompositionDeploy.class);
+ assertSerializeBehaviour(orig);
}
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021,2023-2024 Nordix Foundation.
+ * Copyright (C) 2021,2023-2024,2026 OpenInfra Foundation Europe. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.clamp.models.acm.messages.kafka.participant;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
assertEquals(removeVariableFields(object.toString()), removeVariableFields(other.toString()));
}
+
+ /**
+ * Check if the null fields in properties are omitted in serialization.
+ * @param object the Object
+ * @throws CoderException if object is not serializable
+ */
+ public static <T> void assertSerializeBehaviour(Object object) throws CoderException {
+ var standardCoder = new StandardCoder();
+ var json = standardCoder.encode(object);
+ assertFalse(json.contains("nullProperty"));
+ assertTrue(json.contains("testProperty"));
+ }
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
+ * Copyright (C) 2025-2026 OpenInfra Foundation Europe. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageUtils.assertSerializable;
+import static org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageUtils.assertSerializeBehaviour;
import static org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageUtils.removeVariableFields;
+import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
@Test
void testCopyConstructor() throws CoderException {
- var acElement = new AcElementDeploy();
- acElement.setId(UUID.randomUUID());
+ var acElementDeploy = new AcElementDeploy();
+ acElementDeploy.setId(UUID.randomUUID());
var id = new ToscaConceptIdentifier("id", "1.2.3");
- acElement.setDefinition(id);
+ acElementDeploy.setDefinition(id);
+ var properties = new HashMap<String, Object>();
+ properties.put("testProperty", "dummy");
+ properties.put("nullProperty", null);
+ acElementDeploy.setProperties(properties);
var participantDeploy = new ParticipantDeploy();
participantDeploy.setParticipantId(CommonTestData.getParticipantId());
- participantDeploy.setAcElementList(List.of(acElement));
+ participantDeploy.setAcElementList(List.of(acElementDeploy));
var orig = new PropertiesUpdate();
orig.setParticipantUpdatesList(List.of(participantDeploy));
orig.setCompositionId(UUID.randomUUID());
var other = new PropertiesUpdate(orig);
assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
assertSerializable(orig, PropertiesUpdate.class);
+ assertSerializeBehaviour(orig);
}
}
package org.onap.policy.common.utils.coder;
+import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
mapper.configure(SerializationFeature.FAIL_ON_SELF_REFERENCES, false);
// Don't write self references as null, just ignore them
mapper.configure(SerializationFeature.WRITE_SELF_REFERENCES_AS_NULL, false);
-
+ // Ignore null fields during serialization
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
// Register modules for Java 8 time support (JSR310)
mapper.findAndRegisterModules();
package org.onap.policy.common.utils.coder;
+import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
this.mapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
// Configure to handle circular references
this.mapper.configure(SerializationFeature.FAIL_ON_SELF_REFERENCES, false);
+ // Ignore null fields during serialization
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
/**