org.immutables.fixture.GsonAdaptersSillySub2 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 SillySub2}.
* @see ImmutableSillySub2
*/
@SuppressWarnings({"all", "MethodCanBeStatic"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@org.immutables.value.Generated(from = "org.immutables.fixture", generator = "Gsons")
public final class GsonAdaptersSillySub2 implements TypeAdapterFactory {
@SuppressWarnings({"unchecked", "rawtypes"}) // safe unchecked, types are verified in runtime
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (SillySub2TypeAdapter.adapts(type)) {
return (TypeAdapter) new SillySub2TypeAdapter(gson);
}
return null;
}
@Override
public String toString() {
return "GsonAdaptersSillySub2(SillySub2)";
}
@org.immutables.value.Generated(from = "SillySub2", generator = "Gsons")
@SuppressWarnings({"unchecked", "rawtypes"}) // safe unchecked, types are verified in runtime
private static class SillySub2TypeAdapter extends TypeAdapter {
SillySub2TypeAdapter(Gson gson) {
}
static boolean adapts(TypeToken> type) {
return SillySub2.class == type.getRawType()
|| ImmutableSillySub2.class == type.getRawType();
}
@Override
public void write(JsonWriter out, SillySub2 value) throws IOException {
if (value == null) {
out.nullValue();
} else {
writeSillySub2(out, value);
}
}
@Override
public SillySub2 read(JsonReader in) throws IOException {
return readSillySub2(in);
}
private void writeSillySub2(JsonWriter out, SillySub2 instance)
throws IOException {
out.beginObject();
out.name("b");
out.value(instance.b());
out.endObject();
}
private SillySub2 readSillySub2(JsonReader in)
throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
ImmutableSillySub2.Builder builder = ImmutableSillySub2.builder();
in.beginObject();
while (in.hasNext()) {
eachAttribute(in, builder);
}
in.endObject();
return builder.build();
}
private void eachAttribute(JsonReader in, ImmutableSillySub2.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, ImmutableSillySub2.Builder builder)
throws IOException {
builder.b(in.nextString());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy