org.immutables.fixture.GsonAdaptersSillySub1 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 javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.processing.Generated;
/**
* A {@code TypeAdapterFactory} that handles all of the immutable types generated under {@code SillySub1}.
* @see ImmutableSillySub1
*/
@SuppressWarnings({"all", "MethodCanBeStatic"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@org.immutables.value.Generated(from = "org.immutables.fixture", generator = "Gsons")
public final class GsonAdaptersSillySub1 implements TypeAdapterFactory {
@SuppressWarnings({"unchecked", "rawtypes"}) // safe unchecked, types are verified in runtime
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (SillySub1TypeAdapter.adapts(type)) {
return (TypeAdapter) new SillySub1TypeAdapter(gson);
}
return null;
}
@Override
public String toString() {
return "GsonAdaptersSillySub1(SillySub1)";
}
@org.immutables.value.Generated(from = "SillySub1", generator = "Gsons")
@SuppressWarnings({"unchecked", "rawtypes"}) // safe unchecked, types are verified in runtime
private static class SillySub1TypeAdapter extends TypeAdapter {
SillySub1TypeAdapter(Gson gson) {
}
static boolean adapts(TypeToken> type) {
return SillySub1.class == type.getRawType()
|| ImmutableSillySub1.class == type.getRawType();
}
@Override
public void write(JsonWriter out, SillySub1 value) throws IOException {
if (value == null) {
out.nullValue();
} else {
writeSillySub1(out, value);
}
}
@Override
public SillySub1 read(JsonReader in) throws IOException {
return readSillySub1(in);
}
private void writeSillySub1(JsonWriter out, SillySub1 instance)
throws IOException {
out.beginObject();
out.name("a");
out.value(instance.a());
out.endObject();
}
private SillySub1 readSillySub1(JsonReader in)
throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
ImmutableSillySub1.Builder builder = ImmutableSillySub1.builder();
in.beginObject();
while (in.hasNext()) {
eachAttribute(in, builder);
}
in.endObject();
return builder.build();
}
private void eachAttribute(JsonReader in, ImmutableSillySub1.Builder builder)
throws IOException {
String attributeName = in.nextName();
switch (attributeName.charAt(0)) {
case 'a':
if ("a".equals(attributeName)) {
readInA(in, builder);
return;
}
break;
default:
}
in.skipValue();
}
private void readInA(JsonReader in, ImmutableSillySub1.Builder builder)
throws IOException {
builder.a(in.nextInt());
}
}
}