com.codepoetics.octarine.json.serialisation.ListSerialiser Maven / Gradle / Ivy
package com.codepoetics.octarine.json.serialisation;
import com.fasterxml.jackson.core.JsonGenerator;
import java.io.IOException;
import java.util.Collection;
public final class ListSerialiser implements SafeSerialiser> {
public static ListSerialiser writingItemsWith(Serialiser super T> itemSerialiser) {
return new ListSerialiser<>(itemSerialiser);
}
private final Serialiser super T> itemSerialiser;
private ListSerialiser(Serialiser super T> itemSerialiser) {
this.itemSerialiser = itemSerialiser;
}
@Override
public void unsafeAccept(JsonGenerator j, Collection extends T> ts) throws IOException {
j.writeStartArray();
ts.forEach(t -> itemSerialiser.accept(j, t));
j.writeEndArray();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy