This is an automated email from the ASF dual-hosted git repository.

pvillard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 1c081c1554 NIFI-15292 Refactored State Serialization in GetAsanaObject
1c081c1554 is described below

commit 1c081c15544b8459d69daaae2056f0f433cafce6
Author: exceptionfactory <[email protected]>
AuthorDate: Wed Dec 3 21:36:16 2025 -0600

    NIFI-15292 Refactored State Serialization in GetAsanaObject
    
    - Replaced generic Java Object serialization with simplified String and Map 
serialization using Gson
    
    Signed-off-by: Pierre Villard <[email protected]>
    
    This closes #10599.
---
 .../nifi/processors/asana/GetAsanaObject.java      |  4 +-
 ...GenericObjectSerDe.java => MapStringSerDe.java} | 43 ++++++-----
 .../{GenericObjectSerDe.java => StringSerDe.java}  | 32 ++++----
 .../processors/asana/GenericObjectSerDeTest.java   | 86 ----------------------
 .../nifi/processors/asana/MapStringSerDeTest.java  | 66 +++++++++++++++++
 .../nifi/processors/asana/StringSerDeTest.java     | 54 ++++++++++++++
 6 files changed, 161 insertions(+), 124 deletions(-)

diff --git 
a/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/GetAsanaObject.java
 
b/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/GetAsanaObject.java
index c689a85bde..3edb57a8d1 100644
--- 
a/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/GetAsanaObject.java
+++ 
b/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/GetAsanaObject.java
@@ -210,8 +210,8 @@ public class GetAsanaObject extends AbstractProcessor {
             REL_UPDATED,
             REL_REMOVED
     );
-    protected static final GenericObjectSerDe<String> STATE_MAP_KEY_SERIALIZER 
= new GenericObjectSerDe<>();
-    protected static final GenericObjectSerDe<Map<String, String>> 
STATE_MAP_VALUE_SERIALIZER = new GenericObjectSerDe<>();
+    protected static final StringSerDe STATE_MAP_KEY_SERIALIZER = new 
StringSerDe();
+    protected static final MapStringSerDe STATE_MAP_VALUE_SERIALIZER = new 
MapStringSerDe();
 
     private volatile AsanaObjectFetcher objectFetcher;
     private volatile Integer batchSize;
diff --git 
a/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/GenericObjectSerDe.java
 
b/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/MapStringSerDe.java
similarity index 55%
copy from 
nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/GenericObjectSerDe.java
copy to 
nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/MapStringSerDe.java
index 4664c4a9c2..692bedcd33 100644
--- 
a/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/GenericObjectSerDe.java
+++ 
b/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/MapStringSerDe.java
@@ -16,42 +16,51 @@
  */
 package org.apache.nifi.processors.asana;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 import org.apache.nifi.distributed.cache.client.Deserializer;
 import org.apache.nifi.distributed.cache.client.Serializer;
 import 
org.apache.nifi.distributed.cache.client.exception.DeserializationException;
 import 
org.apache.nifi.distributed.cache.client.exception.SerializationException;
 
-public class GenericObjectSerDe <V> implements Serializer<V>, Deserializer<V> {
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+
+public class MapStringSerDe implements Serializer<Map<String, String>>, 
Deserializer<Map<String, String>> {
+
+    private static final Charset CHARACTER_SET = StandardCharsets.UTF_8;
+
+    private static final Gson GSON = new Gson();
+
+    private static final TypeToken<Map<String, String>> MAP_TYPE_TOKEN = new 
TypeToken<>() { };
 
     @Override
-    @SuppressWarnings("unchecked")
-    public V deserialize(byte[] value) throws DeserializationException, 
IOException {
+    public Map<String, String> deserialize(final byte[] value) throws 
DeserializationException, IOException {
         if (value == null || value.length == 0) {
             return null;
         }
 
-        try (ByteArrayInputStream bis = new ByteArrayInputStream(value)) {
-            try (ObjectInputStream objectInputStream = new 
ObjectInputStream(bis)) {
-                return (V) objectInputStream.readObject();
-            } catch (ClassNotFoundException e) {
-                throw new DeserializationException(e);
-            }
+        try (Reader reader = new InputStreamReader(new 
ByteArrayInputStream(value), CHARACTER_SET)) {
+            return GSON.fromJson(reader, MAP_TYPE_TOKEN);
         }
     }
 
     @Override
-    public void serialize(V value, OutputStream output) throws 
SerializationException, IOException {
+    public void serialize(final Map<String, String> value, final OutputStream 
output) throws SerializationException, IOException {
         if (value == null) {
             return;
         }
 
-        try (ObjectOutputStream objectOutputStream = new 
ObjectOutputStream(output)) {
-            objectOutputStream.writeObject(value);
+        try (Writer writer = new OutputStreamWriter(output, CHARACTER_SET)) {
+            GSON.toJson(value, writer);
         }
     }
 }
diff --git 
a/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/GenericObjectSerDe.java
 
b/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/StringSerDe.java
similarity index 60%
rename from 
nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/GenericObjectSerDe.java
rename to 
nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/StringSerDe.java
index 4664c4a9c2..ee70d3cecb 100644
--- 
a/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/GenericObjectSerDe.java
+++ 
b/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/StringSerDe.java
@@ -16,42 +16,36 @@
  */
 package org.apache.nifi.processors.asana;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
 import org.apache.nifi.distributed.cache.client.Deserializer;
 import org.apache.nifi.distributed.cache.client.Serializer;
 import 
org.apache.nifi.distributed.cache.client.exception.DeserializationException;
 import 
org.apache.nifi.distributed.cache.client.exception.SerializationException;
 
-public class GenericObjectSerDe <V> implements Serializer<V>, Deserializer<V> {
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+
+public class StringSerDe implements Serializer<String>, Deserializer<String> {
+
+    private static final Charset CHARACTER_SET = StandardCharsets.UTF_8;
 
     @Override
-    @SuppressWarnings("unchecked")
-    public V deserialize(byte[] value) throws DeserializationException, 
IOException {
+    public String deserialize(final byte[] value) throws 
DeserializationException {
         if (value == null || value.length == 0) {
             return null;
         }
 
-        try (ByteArrayInputStream bis = new ByteArrayInputStream(value)) {
-            try (ObjectInputStream objectInputStream = new 
ObjectInputStream(bis)) {
-                return (V) objectInputStream.readObject();
-            } catch (ClassNotFoundException e) {
-                throw new DeserializationException(e);
-            }
-        }
+        return new String(value, CHARACTER_SET);
     }
 
     @Override
-    public void serialize(V value, OutputStream output) throws 
SerializationException, IOException {
+    public void serialize(final String value, final OutputStream output) 
throws SerializationException, IOException {
         if (value == null) {
             return;
         }
 
-        try (ObjectOutputStream objectOutputStream = new 
ObjectOutputStream(output)) {
-            objectOutputStream.writeObject(value);
-        }
+        final byte[] bytes = value.getBytes(CHARACTER_SET);
+        output.write(bytes);
     }
 }
diff --git 
a/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/test/java/org/apache/nifi/processors/asana/GenericObjectSerDeTest.java
 
b/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/test/java/org/apache/nifi/processors/asana/GenericObjectSerDeTest.java
deleted file mode 100644
index a5c0effaef..0000000000
--- 
a/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/test/java/org/apache/nifi/processors/asana/GenericObjectSerDeTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.nifi.processors.asana;
-
-import static java.util.Collections.singletonMap;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import org.junit.jupiter.api.Test;
-
-public class GenericObjectSerDeTest {
-
-    @Test
-    public void testString1() throws IOException {
-        String expected = "Lorem Ipsum";
-        String actual = serializeAndThenDeserialize(expected);
-        assertEquals(expected, actual);
-    }
-
-    @Test
-    public void testString2() throws IOException {
-        String expected = "Foo Bar";
-        String actual = serializeAndThenDeserialize(expected);
-        assertEquals(expected, actual);
-    }
-
-    @Test
-    public void testMap1() throws IOException {
-        Map<String, String> expected = singletonMap("Lorem", "Ipsum");
-        Map<String, String> actual = serializeAndThenDeserialize(expected);
-        assertEquals(expected, actual);
-    }
-
-    @Test
-    public void testMap2() throws IOException {
-        Map<String, String> expected = new LinkedHashMap<>();
-        expected.put("Lorem", "Ipsum");
-        expected.put("Foo", "Bar");
-        Map<String, String> actual = serializeAndThenDeserialize(expected);
-        assertEquals(expected, actual);
-    }
-
-    @Test
-    public void testMap3() throws IOException {
-        Map<String, Map<String, Integer>> expected = new LinkedHashMap<>();
-        expected.put("Lorem", singletonMap("Ipsum", 1));
-        expected.put("Foo", singletonMap("Bar", 2));
-        Map<String, Map<String, Integer>> actual = 
serializeAndThenDeserialize(expected);
-        assertEquals(expected, actual);
-    }
-
-    @Test
-    public void testDeserializingNullInput() throws IOException {
-        assertNull(new GenericObjectSerDe<>().deserialize(null));
-    }
-
-    @Test
-    public void testDeserializingEmptyByteArray() throws IOException {
-        assertNull(new GenericObjectSerDe<>().deserialize(new byte[0]));
-    }
-
-    private <V> V serializeAndThenDeserialize(V value) throws IOException {
-        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
-            new GenericObjectSerDe<V>().serialize(value, bos);
-            return new GenericObjectSerDe<V>().deserialize(bos.toByteArray());
-        }
-    }
-}
diff --git 
a/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/test/java/org/apache/nifi/processors/asana/MapStringSerDeTest.java
 
b/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/test/java/org/apache/nifi/processors/asana/MapStringSerDeTest.java
new file mode 100644
index 0000000000..dce87294fe
--- /dev/null
+++ 
b/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/test/java/org/apache/nifi/processors/asana/MapStringSerDeTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.asana;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Map;
+
+import static java.util.Collections.singletonMap;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class MapStringSerDeTest {
+
+    private final MapStringSerDe serDe = new MapStringSerDe();
+
+    @Test
+    void testSingletonMap() throws IOException {
+        final Map<String, String> expected = singletonMap("Lorem", "Ipsum");
+        final Map<String, String> actual = 
serializeAndThenDeserialize(expected);
+        assertEquals(expected, actual);
+    }
+
+    @Test
+    void testMultipleMap() throws IOException {
+        final Map<String, String> expected = Map.of(
+                "Lorel", "Ipsum",
+                "Foo", "Bar"
+        );
+        final Map<String, String> actual = 
serializeAndThenDeserialize(expected);
+        assertEquals(expected, actual);
+    }
+
+    @Test
+    void testDeserializingNullInput() throws IOException {
+        assertNull(serDe.deserialize(null));
+    }
+
+    @Test
+    void testDeserializingEmptyByteArray() throws IOException {
+        assertNull(serDe.deserialize(new byte[0]));
+    }
+
+    private Map<String, String> serializeAndThenDeserialize(final Map<String, 
String> value) throws IOException {
+        try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) 
{
+            serDe.serialize(value, outputStream);
+            return serDe.deserialize(outputStream.toByteArray());
+        }
+    }
+}
diff --git 
a/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/test/java/org/apache/nifi/processors/asana/StringSerDeTest.java
 
b/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/test/java/org/apache/nifi/processors/asana/StringSerDeTest.java
new file mode 100644
index 0000000000..f12bccc650
--- /dev/null
+++ 
b/nifi-extension-bundles/nifi-asana-bundle/nifi-asana-processors/src/test/java/org/apache/nifi/processors/asana/StringSerDeTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.asana;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class StringSerDeTest {
+
+    private final StringSerDe serDe = new StringSerDe();
+
+    @Test
+    void testString() throws IOException {
+        final String expected = StringSerDe.class.getName();
+        final String actual = serializeAndThenDeserialize(expected);
+        assertEquals(expected, actual);
+    }
+
+    @Test
+    void testDeserializingNullInput() {
+        assertNull(serDe.deserialize(null));
+    }
+
+    @Test
+    void testDeserializingEmptyByteArray() {
+        assertNull(serDe.deserialize(new byte[0]));
+    }
+
+    private String serializeAndThenDeserialize(final String value) throws 
IOException {
+        try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) 
{
+            serDe.serialize(value, outputStream);
+            return serDe.deserialize(outputStream.toByteArray());
+        }
+    }
+}

Reply via email to