package uk.fstr.darwingateway.serializers;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import uk.fstr.darwingateway.bindings.Schedule;
import uk.fstr.darwingateway.bindings.StationMessage;

import java.lang.reflect.Type;

/**
 * Created by gberg on 17/08/15.
 */
public class StationMessageSerializer implements JsonSerializer<StationMessage> {

    @Override
    public JsonElement serialize(StationMessage src, Type typeOfSrc, JsonSerializationContext context) {
        JsonObject object = new JsonObject();

        object.addProperty("smid", src.getId());

        return object;
    }
}

@@ -64,142 +64,50 @@
 son.
-JsonElement;%0Aimport com.google.gson.JsonObject;%0Aimport com.google.gson.JsonSerializationContext;%0Aimport com.google.gson.JsonSerializer
+*;%0Aimport uk.fstr.darwingateway.bindings.A
 ;%0Aim
@@ -146,16 +146,9 @@
 ngs.
-Schedule
+P
 ;%0Aim
@@ -230,16 +230,39 @@
 ct.Type;
+%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -541,24 +541,24 @@
 nObject();%0A%0A
-
         obje
@@ -593,16 +593,1790 @@
 etId());
+%0A        object.addProperty(%22category%22, src.getCat().value());%0A        object.addProperty(%22severity%22, src.getSev());%0A        object.addProperty(%22suppressed%22, src.isSuppress());%0A%0A        JsonArray stations = new JsonArray();%0A        for (StationMessage.Station s: src.getStation()) %7B%0A            JsonObject o = new JsonObject();%0A            o.addProperty(%22crs%22, s.getCrs());%0A            stations.add(o);%0A        %7D%0A        object.add(%22stations%22, stations);%0A%0A        List%3CObject%3E messageContents = src.getMsg().getContent();%0A        StringBuilder mb = new StringBuilder();%0A        for (Object o: messageContents) %7B%0A            if (o.getClass() == String.class) %7B%0A                mb.append((String) o);%0A            %7D else if (o.getClass() == P.class) %7B%0A                for (Object p: ((P) o).getContent()) %7B%0A                    if (p.getClass() == String.class) %7B%0A                        mb.append((String) p);%0A                    %7D else if (p.getClass() == A.class) %7B%0A                        mb.append(%22%3Ca href=%22)%0A                                .append('%22')%0A                                .append(((A) p).getHref())%0A                                .append('%22')%0A                                .append(%22%3E%22)%0A                                .append(((A) p).getValue())%0A                                .append(%22%3C/a%3E%22);%0A                    %7D%0A                %7D%0A            %7D else if (o.getClass() == A.class) %7B%0A                mb.append(%22%3Ca href=%22)%0A                        .append('%22')%0A                        .append(((A) o).getHref())%0A                        .append('%22')%0A                        .append(%22%3E%22)%0A                        .append(((A) o).getValue())%0A                        .append(%22%3C/a%3E%22);%0A            %7D%0A        %7D%0A        object.addProperty(%22message%22, mb.toString());
 %0A%0A      

Implement station message serialization.