aboutsummaryrefslogtreecommitdiffstats
path: root/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-03-03 11:55:02 -0500
committerJim Hahn <jrh3@att.com>2020-03-03 17:46:47 -0500
commit157ece6ced7b093701bd10f3a3cd42c5559529a0 (patch)
treef5c8f42ad3bd1bd5577f1ae1615f285e195bcf95 /gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java
parent361e714960f444d9319dd54186af0e8efede4011 (diff)
Add gson adapters for special field types
Added type adapters for Instant, LocalDateTime, and ZonedDateTime. UUID seems to work already. Added new Coder that offers an alternative encoding for Instant. Issue-ID: POLICY-1625 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I5230fa7fe955d78c5f2da1316cb1504b5875ea84
Diffstat (limited to 'gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java')
-rw-r--r--gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java10
1 files changed, 8 insertions, 2 deletions
diff --git a/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java b/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java
index 75d58f2f..d6e36b39 100644
--- a/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java
+++ b/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. 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.
@@ -30,6 +30,9 @@ import java.io.OutputStreamWriter;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZonedDateTime;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@@ -85,7 +88,10 @@ public class GsonMessageBodyHandler implements MessageBodyReader<Object>, Messag
* @return the configured builder
*/
public static GsonBuilder configBuilder(GsonBuilder builder) {
- return builder.disableHtmlEscaping().registerTypeAdapterFactory(new MapDoubleAdapterFactory());
+ return builder.disableHtmlEscaping().registerTypeAdapterFactory(new MapDoubleAdapterFactory())
+ .registerTypeAdapter(Instant.class, new InstantTypeAdapter())
+ .registerTypeAdapter(LocalDateTime.class, new LocalDateTimeTypeAdapter())
+ .registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeTypeAdapter());
}
@Override