org.immutables.fixture.GsonAdaptersSillyMapHolder Maven / Gradle / Ivy
package org.immutables.fixture;
import com.google.gson.*;
import com.google.gson.reflect.*;
import com.google.gson.stream.*;
import java.io.IOException;
import java.lang.annotation.RetentionPolicy;
import java.util.Map;
import java.util.Set;
import javax.annotation.Generated;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* A {@code TypeAdapterFactory} that handles all of the immutable types generated under {@code SillyMapHolder}.
* @see ImmutableSillyMapHolder
*/
@SuppressWarnings("all")
@Generated({"Gsons.generator", "org.immutables.fixture.SillyMapHolder"})
@ParametersAreNonnullByDefault
public final class GsonAdaptersSillyMapHolder implements TypeAdapterFactory {
@SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (SillyMapHolderTypeAdapter.adapts(type)) {
return (TypeAdapter) new SillyMapHolderTypeAdapter(gson);
}
return null;
}
@Override
public String toString() {
return "GsonAdaptersSillyMapHolder(SillyMapHolder)";
}
@SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
private static class SillyMapHolderTypeAdapter extends TypeAdapter {
private final SillyValue holder1TypeSample = null;
private final SillyMapTup holder3SecondaryTypeSample = null;
private final RetentionPolicy zzTypeSample = null;
private final TypeAdapter holder1TypeAdapter;
private final TypeAdapter holder3SecondaryTypeAdapter;
private final TypeAdapter zzTypeAdapter;
SillyMapHolderTypeAdapter(Gson gson) {
this.holder1TypeAdapter = gson.getAdapter(TypeToken.get(SillyValue.class));
this.holder3SecondaryTypeAdapter = gson.getAdapter(TypeToken.get(SillyMapTup.class));
this.zzTypeAdapter = gson.getAdapter(TypeToken.get(RetentionPolicy.class));
}
static boolean adapts(TypeToken> type) {
return SillyMapHolder.class == type.getRawType()
|| ImmutableSillyMapHolder.class == type.getRawType();
}
@Override
public void write(JsonWriter out, SillyMapHolder value) throws IOException {
if (value == null) {
out.nullValue();
} else {
writeSillyMapHolder(out, value);
}
}
@Override
public SillyMapHolder read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return readSillyMapHolder(in);
}
private void writeSillyMapHolder(JsonWriter out, SillyMapHolder instance)
throws IOException {
out.beginObject();
Map holder1Mapping = instance.holder1();
out.name("holder1");
out.beginObject();
for (Map.Entry e : holder1Mapping.entrySet()) {
String key = holder1TypeAdapter.toJsonTree(e.getKey()).getAsString();
out.name(key);
int value = e.getValue();
out.value(value);
}
out.endObject();
Map holder2Mapping = instance.holder2();
out.name("holder2");
out.beginObject();
for (Map.Entry e : holder2Mapping.entrySet()) {
String key = String.valueOf(e.getKey());
out.name(key);
String value = e.getValue();
out.value(value);
}
out.endObject();
Map holder3Mapping = instance.holder3();
out.name("holder3");
out.beginObject();
for (Map.Entry e : holder3Mapping.entrySet()) {
String key = e.getKey();
out.name(key);
SillyMapTup value = e.getValue();
holder3SecondaryTypeAdapter.write(out, value);
}
out.endObject();
Set zzElements = instance.zz();
out.name("zz");
out.beginArray();
for (RetentionPolicy e : zzElements) {
zzTypeAdapter.write(out, e);
}
out.endArray();
out.endObject();
}
private SillyMapHolder readSillyMapHolder(JsonReader in)
throws IOException {
ImmutableSillyMapHolder.Builder builder = ImmutableSillyMapHolder.builder();
in.beginObject();
while (in.hasNext()) {
eachAttribute(in, builder);
}
in.endObject();
return builder.build();
}
private void eachAttribute(JsonReader in, ImmutableSillyMapHolder.Builder builder)
throws IOException {
String attributeName = in.nextName();
switch (attributeName.charAt(0)) {
case 'h':
if ("holder1".equals(attributeName)) {
readInHolder1(in, builder);
return;
}
if ("holder2".equals(attributeName)) {
readInHolder2(in, builder);
return;
}
if ("holder3".equals(attributeName)) {
readInHolder3(in, builder);
return;
}
break;
case 'z':
if ("zz".equals(attributeName)) {
readInZz(in, builder);
return;
}
break;
default:
}
in.skipValue();
}
private void readInHolder1(JsonReader in, ImmutableSillyMapHolder.Builder builder)
throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
} else {
in.beginObject();
while(in.hasNext()) {
String rawKey = in.nextName();
SillyValue key = holder1TypeAdapter.fromJsonTree(new JsonPrimitive(rawKey));
int value = in.nextInt();
builder.putHolder1(key, value);
}
in.endObject();
}
}
private void readInHolder2(JsonReader in, ImmutableSillyMapHolder.Builder builder)
throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
} else {
in.beginObject();
while(in.hasNext()) {
String rawKey = in.nextName();
int key = Integer.parseInt(rawKey);
String value = in.nextString();
builder.putHolder2(key, value);
}
in.endObject();
}
}
private void readInHolder3(JsonReader in, ImmutableSillyMapHolder.Builder builder)
throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
} else {
in.beginObject();
while(in.hasNext()) {
String rawKey = in.nextName();
String key = rawKey;
SillyMapTup value = holder3SecondaryTypeAdapter.read(in);
builder.putHolder3(key, value);
}
in.endObject();
}
}
private void readInZz(JsonReader in, ImmutableSillyMapHolder.Builder builder)
throws IOException {
if (in.peek() == JsonToken.BEGIN_ARRAY) {
in.beginArray();
while(in.hasNext()) {
RetentionPolicy value = zzTypeAdapter.read(in);
builder.addZz(value);
}
in.endArray();
} else if (in.peek() == JsonToken.NULL) {
in.nextNull();
} else {
RetentionPolicy value = zzTypeAdapter.read(in);
builder.addZz(value);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy