summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'daemon')
-rw-r--r--daemon/src/main/java/org/openslx/taskmanager/network/RequestParser.java5
-rw-r--r--daemon/src/main/java/org/openslx/taskmanager/util/BoundedLogSerializer.java28
2 files changed, 32 insertions, 1 deletions
diff --git a/daemon/src/main/java/org/openslx/taskmanager/network/RequestParser.java b/daemon/src/main/java/org/openslx/taskmanager/network/RequestParser.java
index 2d46c5d..e1f883e 100644
--- a/daemon/src/main/java/org/openslx/taskmanager/network/RequestParser.java
+++ b/daemon/src/main/java/org/openslx/taskmanager/network/RequestParser.java
@@ -4,10 +4,13 @@ import java.nio.charset.StandardCharsets;
import java.util.zip.Deflater;
import org.apache.log4j.Logger;
+import org.openslx.taskmanager.api.BoundedLog;
import org.openslx.taskmanager.api.TaskStatus;
import org.openslx.taskmanager.main.Taskmanager;
+import org.openslx.taskmanager.util.BoundedLogSerializer;
import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
public class RequestParser
{
@@ -16,7 +19,7 @@ public class RequestParser
/**
* Our very own gson instance (for serializing replies)
*/
- private final Gson sendGson = new Gson();
+ private final Gson sendGson = new GsonBuilder().registerTypeAdapter( BoundedLog.class, new BoundedLogSerializer() ).create();
/**
* Same for the deflater
diff --git a/daemon/src/main/java/org/openslx/taskmanager/util/BoundedLogSerializer.java b/daemon/src/main/java/org/openslx/taskmanager/util/BoundedLogSerializer.java
new file mode 100644
index 0000000..1a43366
--- /dev/null
+++ b/daemon/src/main/java/org/openslx/taskmanager/util/BoundedLogSerializer.java
@@ -0,0 +1,28 @@
+package org.openslx.taskmanager.util;
+
+import java.lang.reflect.Type;
+
+import org.openslx.taskmanager.api.BoundedLog;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+
+public class BoundedLogSerializer implements JsonSerializer<BoundedLog>
+{
+
+ @Override
+ public JsonElement serialize( BoundedLog src, Type typeOfSrc, JsonSerializationContext context )
+ {
+ StringBuilder sb = new StringBuilder( 500 );
+ for ( String s : src ) {
+ sb.append( s );
+ if ( src.implicitNewlines ) {
+ sb.append( '\n' );
+ }
+ }
+ return new JsonPrimitive( sb.toString() );
+ }
+
+}