org.immutables.fixture.GsonAdaptersSillyMapTup Maven / Gradle / Ivy
package org.immutables.fixture;
import com.google.common.collect.ImmutableMap;
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 javax.annotation.Generated;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* A {@code TypeAdapterFactory} that handles all of the immutable types generated under {@code SillyMapTup}.
* @see ImmutableSillyMapTup
*/
@SuppressWarnings("all")
@Generated({"Gsons.generator", "org.immutables.fixture.SillyMapTup"})
@ParametersAreNonnullByDefault
public final class GsonAdaptersSillyMapTup implements TypeAdapterFactory {
@SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (SillyMapTupTypeAdapter.adapts(type)) {
return (TypeAdapter) new SillyMapTupTypeAdapter(gson);
}
return null;
}
@Override
public String toString() {
return "GsonAdaptersSillyMapTup(SillyMapTup)";
}
@SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
private static class SillyMapTupTypeAdapter extends TypeAdapter {
private final RetentionPolicy holder1TypeSample = null;
private final TypeAdapter holder1TypeAdapter;
SillyMapTupTypeAdapter(Gson gson) {
this.holder1TypeAdapter = gson.getAdapter(TypeToken.get(RetentionPolicy.class));
}
static boolean adapts(TypeToken> type) {
return SillyMapTup.class == type.getRawType()
|| ImmutableSillyMapTup.class == type.getRawType();
}
@Override
public void write(JsonWriter out, SillyMapTup value) throws IOException {
if (value == null) {
out.nullValue();
} else {
writeSillyMapTup(out, value);
}
}
@Override
public SillyMapTup read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return readSillyMapTup(in);
}
private void writeSillyMapTup(JsonWriter out, SillyMapTup instance)
throws IOException {
out.beginArray();
Map holder1Mapping = instance.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();
out.value(instance.value());
out.endArray();
}
private SillyMapTup readSillyMapTup(JsonReader in)
throws IOException {
in.beginArray();
SillyMapTup instance = ImmutableSillyMapTup.of(
readParameterHolder1(in),
readParameterValue(in));
in.endArray();
return instance;
}
private Map readParameterHolder1(JsonReader in)
throws IOException {
ImmutableMap.Builder mappings = ImmutableMap.builder();
if (in.peek() == JsonToken.NULL) {
in.nextNull();
} else {
in.beginObject();
while(in.hasNext()) {
String rawKey = in.nextName();
RetentionPolicy key = holder1TypeAdapter.fromJsonTree(new JsonPrimitive(rawKey));
int value = in.nextInt();
mappings.put(key, value);
}
in.endObject();
}
return mappings.build();
}
private int readParameterValue(JsonReader in)
throws IOException {
return in.nextInt();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy