borg.immutables.fixture.packoutput.impl.GsonAdaptersPacks 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 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.ParametersAreNonnullByDefault;
import javax.annotation.processing.Generated;
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", "MethodCanBeStatic"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@org.immutables.value.Generated(from = "borg.immutables.fixture.packoutput.impl", generator = "Gsons")
public final class GsonAdaptersPacks implements TypeAdapterFactory {
@SuppressWarnings({"unchecked", "rawtypes"}) // 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)";
}
@org.immutables.value.Generated(from = "org.immutables.fixture.packoutput.Packs.Perk", generator = "Gsons")
@SuppressWarnings({"unchecked", "rawtypes"}) // 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 {
return readPerk(in);
}
private void writePerk(JsonWriter out, Packs.Perk instance)
throws IOException {
out.beginObject();
out.endObject();
}
private static Packs.Perk readPerk(JsonReader in)
throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
ImmutablePacks.Perk.Builder builder = ImmutablePacks.Perk.builder();
in.skipValue();
return builder.build();
}
}
@org.immutables.value.Generated(from = "org.immutables.fixture.packoutput.Packs", generator = "Gsons")
@SuppressWarnings({"unchecked", "rawtypes"}) // safe unchecked, types are verified in runtime
private static class PacksTypeAdapter extends TypeAdapter {
public final Packs.Perk perkTypeSample = null;
private final TypeAdapter perkTypeAdapter;
PacksTypeAdapter(Gson gson) {
this.perkTypeAdapter = gson.getAdapter( 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 {
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 {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
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 - 2024 Weber Informatics LLC | Privacy Policy