package ru.lanwen.jenkins.juseppe.gen;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;
import ru.lanwen.jenkins.juseppe.beans.Plugin;

import java.lang.reflect.Type;
import java.util.List;

/**
 * User: lanwen
 * Date: 28.01.15
 * Time: 1:34
 */
public class PluginListSerializer implements JsonSerializer<List<Plugin>> {

    public static final Type PLUGIN_LIST_TYPE = new TypeToken<List<Plugin>>() {
    }.getType();

    @Override
    public JsonElement serialize(List<Plugin> src, Type typeOfSrc, JsonSerializationContext context) {
        JsonObject jsonObject = new JsonObject();

        for(Plugin plugin : src) {
            jsonObject.add(plugin.getName(), context.serialize(plugin));
        }

        return jsonObject;
    }
}
@@ -337,16 +337,148 @@
 .List;%0A%0A
+import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;%0Aimport static org.apache.commons.lang3.StringUtils.trimToEmpty;%0A%0A
 /**%0A * U
@@ -879,16 +879,17 @@
      for
+ 
 (Plugin 
@@ -935,25 +935,225 @@
 add(
-plugin.getName(),
+%0A                    defaultIfEmpty(%0A                            plugin.getName(), %0A                            trimToEmpty(plugin.getTitle()).replace(%22 %22, %22-%22).toLowerCase()%0A                    ),%0A                   
  con

fix - don't fail in case of empty name