HttpLookupUri is now serializable again
[so.git] / common / src / main / java / org / onap / so / client / aai / entities / uri / HttpLookupUri.java
index f086a6a..37d21b3 100644 (file)
@@ -21,6 +21,8 @@
 package org.onap.so.client.aai.entities.uri;
 
 import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.net.URI;
 import java.util.Map;
 import java.util.Optional;
@@ -42,7 +44,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 
 public abstract class HttpLookupUri extends AAISimpleUri implements HttpAwareUri {
 
-    private Optional<String> cachedValue = Optional.empty();
+    private transient Optional<String> cachedValue = Optional.empty();
     private final AAIObjectType aaiType;
 
     protected HttpLookupUri(AAIObjectType type, Object... values) {
@@ -78,8 +80,7 @@ public abstract class HttpLookupUri extends AAISimpleUri implements HttpAwareUri
                 throw new GraphInventoryPayloadException("could not map payload: " + resultJson, e);
             }
         }
-        Optional<String> cachedValueOpt = this.getCachedValue();
-        return cachedValueOpt.isPresent() ? cachedValueOpt.get() : "";
+        return cachedValue.get();
     }
 
     protected Optional<String> extractRelatedLink(String jsonString) throws IOException {
@@ -139,6 +140,22 @@ public abstract class HttpLookupUri extends AAISimpleUri implements HttpAwareUri
         return new AAIResourcesClient();
     }
 
+    private void writeObject(ObjectOutputStream oos) throws IOException {
+
+        oos.writeUTF(this.cachedValue.orElse(""));
+    }
+
+    private void readObject(ObjectInputStream ois) throws IOException {
+
+        String value = ois.readUTF();
+        if ("".equals(value)) {
+            this.cachedValue = Optional.empty();
+        } else {
+            this.cachedValue = Optional.ofNullable(value);
+        }
+
+    }
+
     @Override
     public abstract URI buildNoNetwork();
 }