com.github.nmorel.gwtjackson.client.ser.IterableJsonSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gwt-jackson Show documentation
Show all versions of gwt-jackson Show documentation
gwt-jackson is a GWT JSON serializer/deserializer mechanism based on Jackson annotations
package com.github.nmorel.gwtjackson.client.ser;
import javax.annotation.Nonnull;
import java.io.IOException;
import com.github.nmorel.gwtjackson.client.JsonSerializationContext;
import com.github.nmorel.gwtjackson.client.JsonSerializer;
import com.github.nmorel.gwtjackson.client.stream.JsonWriter;
/**
* Default {@link JsonSerializer} implementation for {@link Iterable}.
*
* @param Type of the elements inside the {@link Iterable}
*
* @author Nicolas Morel
*/
public class IterableJsonSerializer, T> extends JsonSerializer {
/**
* @param serializer {@link JsonSerializer} used to serialize the objects inside the {@link Iterable}.
* @param Type of the elements inside the {@link Iterable}
*
* @return a new instance of {@link IterableJsonSerializer}
*/
public static , T> IterableJsonSerializer newInstance( JsonSerializer serializer ) {
return new IterableJsonSerializer( serializer );
}
protected final JsonSerializer serializer;
/**
* @param serializer {@link JsonSerializer} used to serialize the objects inside the {@link Iterable}.
*/
protected IterableJsonSerializer( JsonSerializer serializer ) {
if ( null == serializer ) {
throw new IllegalArgumentException( "serializer cannot be null" );
}
this.serializer = serializer;
}
@Override
public void doSerialize( JsonWriter writer, @Nonnull I values, JsonSerializationContext ctx ) throws IOException {
writer.beginArray();
for ( T value : values ) {
serializer.serialize( writer, value, ctx );
}
writer.endArray();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy