package edu.neu.ccs.pyramid.feature;

import java.util.List;

/**
 * Created by chengli on 10/6/16.
 */
public class CodeDescription extends Feature {
    private static final long serialVersionUID = 1L;
    private List<String> description;
    private int percentage;
    private String field;

    public CodeDescription(List<String> description, int percentage, String field) {
        this.description = description;
        this.percentage = percentage;
        this.field = field;
    }

    public List<String> getDescription() {
        return description;
    }

    public int getPercentage() {
        return percentage;
    }

    public String getField() {
        return field;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("CodeDescription{");
        sb.append("description=").append(description);
        sb.append(", percentage=").append(percentage);
        sb.append(", field='").append(field).append('\'');
        sb.append('}');
        return sb.toString();
    }
}

@@ -31,16 +31,329 @@
 ature;%0A%0A
+import com.fasterxml.jackson.core.JsonGenerator;%0Aimport com.fasterxml.jackson.core.JsonProcessingException;%0Aimport com.fasterxml.jackson.databind.JsonSerializer;%0Aimport com.fasterxml.jackson.databind.SerializerProvider;%0Aimport com.fasterxml.jackson.databind.annotation.JsonSerialize;%0A%0Aimport java.io.IOException;%0A
 import j
@@ -410,16 +410,73 @@
 16.%0A */%0A
+@JsonSerialize(using = CodeDescription.Serializer.class)%0A
 public c
@@ -1408,11 +1408,953 @@
 );%0A    %7D
+%0A%0A    public static class Serializer extends JsonSerializer%3CCodeDescription%3E %7B%0A        @Override%0A        public void serialize(CodeDescription feature, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException %7B%0A            StringBuilder stringBuilder = new StringBuilder();%0A            for (String term: feature.description)%7B%0A                stringBuilder.append(term).append(%22 %22);%0A            %7D%0A            jsonGenerator.writeStartObject();%0A            jsonGenerator.writeNumberField(%22index%22, feature.index);%0A            jsonGenerator.writeStringField(%22type%22,%22code description%22);%0A            jsonGenerator.writeStringField(%22field%22,feature.field);%0A            jsonGenerator.writeStringField(%22description%22,stringBuilder.toString());%0A            jsonGenerator.writeNumberField(%22minimum should match percent%22,feature.percentage);%0A%0A            jsonGenerator.writeEndObject();%0A        %7D%0A    %7D
 %0A%7D%0A

code description to json