package org.atlasapi.output.annotation;

import java.io.IOException;

import org.atlasapi.content.Described;
import org.atlasapi.content.Item;
import org.atlasapi.media.entity.Publisher;
import org.atlasapi.output.EntityWriter;
import org.atlasapi.output.FieldWriter;
import org.atlasapi.output.OutputContext;
import org.atlasapi.output.writers.SourceWriter;
import org.atlasapi.topic.Topic;

public class DescriptionAnnotation<T extends Described> extends
        OutputAnnotation<T> {

    private final EntityWriter<Publisher> publisherWriter = SourceWriter.sourceWriter("source");

    @Override
    public void write(T entity, FieldWriter writer, OutputContext ctxt) throws IOException {
        writer.writeObject(publisherWriter, entity.getSource(), ctxt);
        if (entity instanceof Topic) {
            Topic topic = (Topic) entity;
            writer.writeField("topic_type", topic.getType());
        }
        writer.writeField("title", entity.getTitle());
        writer.writeField("description", entity.getDescription());
        writer.writeField("image", entity.getImage());
        writer.writeField("thumbnail", entity.getThumbnail());
        if(entity instanceof Item) {
            Item item = (Item) entity;
            writer.writeField("duration", item.getDuration());
        }
    }

}
@@ -45,29 +45,42 @@
 ort 
-java.io.IOException;%0A
+com.google.common.primitives.Ints;
 %0Aimp
@@ -399,16 +399,45 @@
 Topic;%0A%0A
+import java.io.IOException;%0A%0A
 public c
@@ -1202,16 +1202,17 @@
       if
+ 
 (entity 
@@ -1226,24 +1226,24 @@
 eof Item) %7B%0A
-
             
@@ -1303,38 +1303,225 @@
 eld(
-%22duration%22, item.getDuration()
+%0A                    %22duration%22,%0A                    item.getDuration() == null%0A                            ? null%0A                            : Ints.saturatedCast(item.getDuration().getStandardSeconds())%0A            
 );%0A 

Fix item-level duration serialization in api (#670)