All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.immutables.fixture.GsonAdaptersSillyIntWrap 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 javax.annotation.Generated;
import javax.annotation.ParametersAreNonnullByDefault;

/**
 * A {@code TypeAdapterFactory} that handles all of the immutable types generated under {@code SillyIntWrap}.
 * @see ImmutableSillyIntWrap
 */
@SuppressWarnings("all")
@Generated({"Gsons.generator", "org.immutables.fixture.SillyIntWrap"})
@ParametersAreNonnullByDefault
public final class GsonAdaptersSillyIntWrap implements TypeAdapterFactory {
  @SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
  @Override
  public  TypeAdapter create(Gson gson, TypeToken type) {
    if (SillyIntWrapTypeAdapter.adapts(type)) {
      return (TypeAdapter) new SillyIntWrapTypeAdapter(gson);
    }
    return null;
  }

  @Override
  public String toString() {
    return "GsonAdaptersSillyIntWrap(SillyIntWrap)";
  }

  @SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
  private static class SillyIntWrapTypeAdapter extends TypeAdapter {

    SillyIntWrapTypeAdapter(Gson gson) {
    } 

    static boolean adapts(TypeToken type) {
      return SillyIntWrap.class == type.getRawType()
          || ImmutableSillyIntWrap.class == type.getRawType();
    }

    @Override
    public void write(JsonWriter out, SillyIntWrap value) throws IOException {
      if (value == null) {
        out.nullValue();
      } else {
        writeSillyIntWrap(out, value);
      }
    }

    @Override
    public SillyIntWrap read(JsonReader in) throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
      }
      return readSillyIntWrap(in);
    }

    private void writeSillyIntWrap(JsonWriter out, SillyIntWrap instance)
        throws IOException {
      out.value(instance.value());
    }

    private SillyIntWrap readSillyIntWrap(JsonReader in)
        throws IOException {
      return ImmutableSillyIntWrap.of(readParameterValue(in));
    }

    private int readParameterValue(JsonReader in)
        throws IOException {
      return in.nextInt();
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy