aboutsummaryrefslogtreecommitdiffstats
path: root/prh-commons
diff options
context:
space:
mode:
Diffstat (limited to 'prh-commons')
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/CommonFunctions.java13
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java8
-rw-r--r--prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java2
3 files changed, 13 insertions, 10 deletions
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/CommonFunctions.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/CommonFunctions.java
index c78146f7..9e5a73da 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/CommonFunctions.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/CommonFunctions.java
@@ -20,17 +20,20 @@
package org.onap.dcaegen2.services.prh.model;
-import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+import com.google.gson.TypeAdapterFactory;
+import java.util.ServiceLoader;
public class CommonFunctions {
- private static Gson gson = new GsonBuilder().create();
-
- private CommonFunctions() {}
+ private CommonFunctions() {
+ }
public static String createJsonBody(ConsumerDmaapModel consumerDmaapModel) {
- return gson.toJson(consumerDmaapModel);
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
+ return gsonBuilder.create().toJson(ImmutableConsumerDmaapModel.builder().ipv4(consumerDmaapModel.getIpv4())
+ .ipv6(consumerDmaapModel.getIpv6()).pnfName(consumerDmaapModel.getPnfName()).build());
}
}
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java
index dae0e59e..7dba211f 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java
@@ -28,15 +28,15 @@ import org.immutables.value.Value;
*/
@Value.Immutable
-@Gson.TypeAdapters
+@Gson.TypeAdapters(fieldNamingStrategy = true)
public interface ConsumerDmaapModel {
- @SerializedName("pnf-name")
+ @SerializedName(value = "pnf-name", alternate = "pnf-name")
String getPnfName();
- @SerializedName("ipaddress-v4-oam")
+ @SerializedName(value = "ipaddress-v4-oam", alternate = "ipaddress-v4-oam")
String getIpv4();
- @SerializedName("ipaddress-v6-oam")
+ @SerializedName(value = "ipaddress-v6-oam", alternate = "ipaddress-v6-oam")
String getIpv6();
}
diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java
index 49b97abd..90e42e38 100644
--- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java
+++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java
@@ -50,7 +50,7 @@ class CommonFunctionsTest {
@Test
void createJsonBody_shouldReturnJsonInString() {
- String expectedResult = "{\"pnfName\":\"NOKnhfsadhff\",\"ipv4\":\"256.22.33.155\",\"ipv6\":\"2001:0db8:85a3:0000:0000:8a2e:0370:7334\"}";
+ String expectedResult = "{\"pnf-name\":\"NOKnhfsadhff\",\"ipaddress-v4-oam\":\"256.22.33.155\",\"ipaddress-v6-oam\":\"2001:0db8:85a3:0000:0000:8a2e:0370:7334\"}";
assertEquals(expectedResult, CommonFunctions.createJsonBody(model));
}
}