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

org.immutables.fixture.GsonAdaptersSillyIntWrap Maven / Gradle / Ivy

There is a newer version: 2.10.1
Show newest version
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.ParametersAreNonnullByDefault;
import javax.annotation.processing.Generated;

/**
 * A {@code TypeAdapterFactory} that handles all of the immutable types generated under {@code SillyIntWrap}.
 * @see ImmutableSillyIntWrap
 */
@SuppressWarnings({"all", "MethodCanBeStatic"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@org.immutables.value.Generated(from = "org.immutables.fixture", generator = "Gsons")
public final class GsonAdaptersSillyIntWrap implements TypeAdapterFactory {
  @SuppressWarnings({"unchecked", "rawtypes"}) // 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)";
  }

  @org.immutables.value.Generated(from = "SillyIntWrap", generator = "Gsons")
  @SuppressWarnings({"unchecked", "rawtypes"}) // 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 {
      return readSillyIntWrap(in);
    }

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy