summaryrefslogtreecommitdiffstats
path: root/daemon/src/main/java/org/openslx/taskmanager/util/ByteArrayDeserializer.java
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/src/main/java/org/openslx/taskmanager/util/ByteArrayDeserializer.java')
-rw-r--r--daemon/src/main/java/org/openslx/taskmanager/util/ByteArrayDeserializer.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/daemon/src/main/java/org/openslx/taskmanager/util/ByteArrayDeserializer.java b/daemon/src/main/java/org/openslx/taskmanager/util/ByteArrayDeserializer.java
new file mode 100644
index 0000000..bb2631f
--- /dev/null
+++ b/daemon/src/main/java/org/openslx/taskmanager/util/ByteArrayDeserializer.java
@@ -0,0 +1,31 @@
+package org.openslx.taskmanager.util;
+
+import java.lang.reflect.Type;
+import java.nio.charset.StandardCharsets;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+
+public class ByteArrayDeserializer implements JsonDeserializer<byte[]>
+{
+
+ @Override
+ public byte[] deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context ) throws JsonParseException
+ {
+ if ( json.isJsonArray() ) {
+ JsonArray ja = json.getAsJsonArray();
+ int len = ja.size();
+ byte[] ba = new byte[ len ];
+ int i = 0;
+ for ( JsonElement el : ja ) {
+ ba[i++] = el.getAsByte();
+ }
+ return ba;
+ }
+ return json.getAsString().getBytes( StandardCharsets.UTF_8 );
+ }
+
+}