xyz.cofe.coll.im.json.jakson.ImListSerializer Maven / Gradle / Ivy
The newest version!
package xyz.cofe.coll.im.json.jakson;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import xyz.cofe.coll.im.ImList;
import java.io.IOException;
@SuppressWarnings("rawtypes")
public class ImListSerializer extends StdSerializer {
public ImListSerializer(){
super((Class) null);
}
public ImListSerializer(Class t) {
super(t);
}
@Override
public void serialize(ImList imList, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeStartArray();
imList.each(obj -> {
try {
gen.writeObject(obj);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
gen.writeEndArray();
}
}