borg.immutables.fixture.packoutput.impl.GsonAdaptersPacks Maven / Gradle / Ivy
package borg.immutables.fixture.packoutput.impl;
import com.google.gson.*;
import com.google.gson.reflect.*;
import com.google.gson.stream.*;
import java.io.IOException;
import javax.annotation.Generated;
import javax.annotation.ParametersAreNonnullByDefault;
import org.immutables.fixture.packoutput.Packs;
/**
* A {@code TypeAdapterFactory} that handles all of the immutable types generated under {@code Packs}.
* @see ImmutablePacks.Perk
* @see ImmutablePacks
*/
@SuppressWarnings("all")
@Generated({"Gsons.generator", "borg.immutables.fixture.packoutput.impl.Packs"})
@ParametersAreNonnullByDefault
public final class GsonAdaptersPacks implements TypeAdapterFactory {
@SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (PerkTypeAdapter.adapts(type)) {
return (TypeAdapter) new PerkTypeAdapter(gson);
}
if (PacksTypeAdapter.adapts(type)) {
return (TypeAdapter) new PacksTypeAdapter(gson);
}
return null;
}
@Override
public String toString() {
return "GsonAdaptersPacks(Perk, Packs)";
}
@SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
private static class PerkTypeAdapter extends TypeAdapter {
PerkTypeAdapter(Gson gson) {}
static boolean adapts(TypeToken> type) {
return Packs.Perk.class == type.getRawType()
|| ImmutablePacks.Perk.class == type.getRawType();
}
@Override
public void write(JsonWriter out, Packs.Perk value) throws IOException {
if (value == null) {
out.nullValue();
} else {
writePerk(out, value);
}
}
@Override
public Packs.Perk read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return readPerk(in);
}
private void writePerk(JsonWriter out, Packs.Perk instance)
throws IOException {
out.beginObject();
out.endObject();
}
private Packs.Perk readPerk(JsonReader in)
throws IOException {
ImmutablePacks.Perk.Builder builder = ImmutablePacks.Perk.builder();
in.skipValue();
return builder.build();
}
}
@SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
private static class PacksTypeAdapter extends TypeAdapter {
private final Packs.Perk perkTypeSample = null;
private final TypeAdapter perkTypeAdapter;
PacksTypeAdapter(Gson gson) {
this.perkTypeAdapter = gson.getAdapter(TypeToken.get(Packs.Perk.class));
}
static boolean adapts(TypeToken> type) {
return Packs.class == type.getRawType()
|| ImmutablePacks.class == type.getRawType();
}
@Override
public void write(JsonWriter out, Packs value) throws IOException {
if (value == null) {
out.nullValue();
} else {
writePacks(out, value);
}
}
@Override
public Packs read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return readPacks(in);
}
private void writePacks(JsonWriter out, Packs instance)
throws IOException {
out.beginObject();
out.name("perk");
perkTypeAdapter.write(out, instance.perk());
out.endObject();
}
private Packs readPacks(JsonReader in)
throws IOException {
ImmutablePacks.Builder builder = ImmutablePacks.builder();
in.beginObject();
while (in.hasNext()) {
eachAttribute(in, builder);
}
in.endObject();
return builder.build();
}
private void eachAttribute(JsonReader in, ImmutablePacks.Builder builder)
throws IOException {
String attributeName = in.nextName();
switch (attributeName.charAt(0)) {
case 'p':
if ("perk".equals(attributeName)) {
readInPerk(in, builder);
return;
}
break;
default:
}
in.skipValue();
}
private void readInPerk(JsonReader in, ImmutablePacks.Builder builder)
throws IOException {
Packs.Perk value = perkTypeAdapter.read(in);
builder.perk(value);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy