org.immutables.fixture.GsonAdaptersSillySub3 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of value-fixture Show documentation
Show all versions of value-fixture Show documentation
Module that contains all tests for the code generation capability
package org.immutables.fixture;
import com.google.gson.*;
import com.google.gson.reflect.*;
import com.google.gson.stream.*;
import java.io.IOException;
import java.util.List;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.processing.Generated;
/**
* A {@code TypeAdapterFactory} that handles all of the immutable types generated under {@code SillySub3}.
* @see ImmutableSillySub3
*/
@SuppressWarnings({"all", "MethodCanBeStatic"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@org.immutables.value.Generated(from = "org.immutables.fixture", generator = "Gsons")
public final class GsonAdaptersSillySub3 implements TypeAdapterFactory {
@SuppressWarnings({"unchecked", "rawtypes"}) // safe unchecked, types are verified in runtime
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (SillySub3TypeAdapter.adapts(type)) {
return (TypeAdapter) new SillySub3TypeAdapter(gson);
}
return null;
}
@Override
public String toString() {
return "GsonAdaptersSillySub3(SillySub3)";
}
@org.immutables.value.Generated(from = "SillySub3", generator = "Gsons")
@SuppressWarnings({"unchecked", "rawtypes"}) // safe unchecked, types are verified in runtime
private static class SillySub3TypeAdapter extends TypeAdapter {
public final Double bTypeSample = null;
private final TypeAdapter bTypeAdapter;
SillySub3TypeAdapter(Gson gson) {
this.bTypeAdapter = gson.getAdapter( Double.class);
}
static boolean adapts(TypeToken> type) {
return SillySub3.class == type.getRawType()
|| ImmutableSillySub3.class == type.getRawType();
}
@Override
public void write(JsonWriter out, SillySub3 value) throws IOException {
if (value == null) {
out.nullValue();
} else {
writeSillySub3(out, value);
}
}
@Override
public SillySub3 read(JsonReader in) throws IOException {
return readSillySub3(in);
}
private void writeSillySub3(JsonWriter out, SillySub3 instance)
throws IOException {
out.beginObject();
List bElements = instance.b();
out.name("b");
out.beginArray();
for (Double e : bElements) {
bTypeAdapter.write(out, e);
}
out.endArray();
out.endObject();
}
private SillySub3 readSillySub3(JsonReader in)
throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
ImmutableSillySub3.Builder builder = ImmutableSillySub3.builder();
in.beginObject();
while (in.hasNext()) {
eachAttribute(in, builder);
}
in.endObject();
return builder.build();
}
private void eachAttribute(JsonReader in, ImmutableSillySub3.Builder builder)
throws IOException {
String attributeName = in.nextName();
switch (attributeName.charAt(0)) {
case 'b':
if ("b".equals(attributeName)) {
readInB(in, builder);
return;
}
break;
default:
}
in.skipValue();
}
private void readInB(JsonReader in, ImmutableSillySub3.Builder builder)
throws IOException {
if (in.peek() == JsonToken.BEGIN_ARRAY) {
in.beginArray();
while(in.hasNext()) {
builder.addB(in.nextDouble());
}
in.endArray();
} else if (in.peek() == JsonToken.NULL) {
in.nextNull();
} else {
builder.addB(in.nextDouble());
}
}
}
}