org.immutables.fixture.nested.GsonAdaptersNonGrouped Maven / Gradle / Ivy
package org.immutables.fixture.nested;
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;
/**
* A {@code TypeAdapterFactory} that handles all of the immutable types generated under {@code NonGrouped}.
* @see ImmutableDabra
* @see ImmutableAbra
* @see ImmutableCadabra
*/
@SuppressWarnings("all")
@Generated({"Gsons.generator", "org.immutables.fixture.nested.NonGrouped"})
@ParametersAreNonnullByDefault
public final class GsonAdaptersNonGrouped implements TypeAdapterFactory {
@SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (DabraTypeAdapter.adapts(type)) {
return (TypeAdapter) new DabraTypeAdapter(gson);
}
if (AbraTypeAdapter.adapts(type)) {
return (TypeAdapter) new AbraTypeAdapter(gson);
}
if (CadabraTypeAdapter.adapts(type)) {
return (TypeAdapter) new CadabraTypeAdapter(gson);
}
return null;
}
@Override
public String toString() {
return "GsonAdaptersNonGrouped(Dabra, Abra, Cadabra)";
}
@SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
private static class DabraTypeAdapter extends TypeAdapter {
DabraTypeAdapter(Gson gson) {
}
static boolean adapts(TypeToken> type) {
return NonGrouped.Dabra.class == type.getRawType()
|| ImmutableDabra.class == type.getRawType();
}
@Override
public void write(JsonWriter out, NonGrouped.Dabra value) throws IOException {
if (value == null) {
out.nullValue();
} else {
writeDabra(out, value);
}
}
@Override
public NonGrouped.Dabra read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return readDabra(in);
}
private void writeDabra(JsonWriter out, NonGrouped.Dabra instance)
throws IOException {
out.value(instance.dabra());
}
private NonGrouped.Dabra readDabra(JsonReader in)
throws IOException {
return ImmutableDabra.of(readParameterDabra(in));
}
private int readParameterDabra(JsonReader in)
throws IOException {
return in.nextInt();
}
}
@SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
private static class AbraTypeAdapter extends TypeAdapter {
AbraTypeAdapter(Gson gson) {}
static boolean adapts(TypeToken> type) {
return NonGrouped.Abra.class == type.getRawType()
|| ImmutableAbra.class == type.getRawType();
}
@Override
public void write(JsonWriter out, NonGrouped.Abra value) throws IOException {
if (value == null) {
out.nullValue();
} else {
writeAbra(out, value);
}
}
@Override
public NonGrouped.Abra read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return readAbra(in);
}
private void writeAbra(JsonWriter out, NonGrouped.Abra instance)
throws IOException {
out.beginObject();
out.endObject();
}
private NonGrouped.Abra readAbra(JsonReader in)
throws IOException {
ImmutableAbra.Builder builder = ImmutableAbra.builder();
in.skipValue();
return builder.build();
}
}
@SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
private static class CadabraTypeAdapter extends TypeAdapter {
CadabraTypeAdapter(Gson gson) {}
static boolean adapts(TypeToken> type) {
return NonGrouped.Cadabra.class == type.getRawType()
|| ImmutableCadabra.class == type.getRawType();
}
@Override
public void write(JsonWriter out, NonGrouped.Cadabra value) throws IOException {
if (value == null) {
out.nullValue();
} else {
writeCadabra(out, value);
}
}
@Override
public NonGrouped.Cadabra read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return readCadabra(in);
}
private void writeCadabra(JsonWriter out, NonGrouped.Cadabra instance)
throws IOException {
out.beginObject();
out.endObject();
}
private NonGrouped.Cadabra readCadabra(JsonReader in)
throws IOException {
in.skipValue();
return ImmutableCadabra.of();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy