org.immutables.fixture.GsonAdaptersSillySub3 Maven / Gradle / Ivy
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.Generated;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* A {@code TypeAdapterFactory} that handles all of the immutable types generated under {@code SillySub3}.
* @see ImmutableSillySub3
*/
@SuppressWarnings("all")
@Generated({"Gsons.generator", "org.immutables.fixture.SillySub3"})
@ParametersAreNonnullByDefault
public final class GsonAdaptersSillySub3 implements TypeAdapterFactory {
@SuppressWarnings({"unchecked", "raw"}) // 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)";
}
@SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
private static class SillySub3TypeAdapter extends TypeAdapter {
SillySub3TypeAdapter(Gson gson) {
}
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 {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
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) {
out.value(e);
}
out.endArray();
out.endObject();
}
private SillySub3 readSillySub3(JsonReader in)
throws IOException {
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());
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy