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

com.neotys.neoload.model.v3.project.scenario.GsonAdaptersStopAfter Maven / Gradle / Ivy

package com.neotys.neoload.model.v3.project.scenario;

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 StopAfter}.
 * @see ImmutableStopAfter
 */
@SuppressWarnings("all")
@Generated({"Gsons.generator", "com.neotys.neoload.model.v3.project.scenario.StopAfter"})
@ParametersAreNonnullByDefault
public final class GsonAdaptersStopAfter implements TypeAdapterFactory {
  @SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
  @Override
  public  TypeAdapter create(Gson gson, TypeToken type) {
    if (StopAfterTypeAdapter.adapts(type)) {
      return (TypeAdapter) new StopAfterTypeAdapter(gson);
    }
    return null;
  }

  @Override
  public String toString() {
    return "GsonAdaptersStopAfter(StopAfter)";
  }

  @SuppressWarnings({"unchecked", "raw"}) // safe unchecked, types are verified in runtime
  private static class StopAfterTypeAdapter extends TypeAdapter {
    public final Object valueTypeSample = null;
    public final StopAfter.Type typeTypeSample = null;
    private final TypeAdapter valueTypeAdapter;
    private final TypeAdapter typeTypeAdapter;

    StopAfterTypeAdapter(Gson gson) {
      this.valueTypeAdapter = gson.getAdapter( Object.class);
      this.typeTypeAdapter = gson.getAdapter( StopAfter.Type.class);
    } 

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

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

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

    private void writeStopAfter(JsonWriter out, StopAfter instance)
        throws IOException {
      out.beginObject();
      Object valueValue = instance.getValue();
      if (valueValue != null) {
        out.name("value");
        valueTypeAdapter.write(out, valueValue);
      } else if (out.getSerializeNulls()) {
        out.name("value");
        out.nullValue();
      }
      StopAfter.Type typeValue = instance.getType();
      if (typeValue != null) {
        out.name("type");
        typeTypeAdapter.write(out, typeValue);
      } else if (out.getSerializeNulls()) {
        out.name("type");
        out.nullValue();
      }
      out.endObject();
    }

    private StopAfter readStopAfter(JsonReader in)
        throws IOException {
      StopAfter.Builder builder = new StopAfter.Builder();
      in.beginObject();
      while (in.hasNext()) {
        eachAttribute(in, builder);
      }
      in.endObject();
      return builder.build();
    }

    private void eachAttribute(JsonReader in, StopAfter.Builder builder)
        throws IOException {
      String attributeName = in.nextName();
      switch (attributeName.charAt(0)) {
      case 'v':
        if ("value".equals(attributeName)) {
          readInValue(in, builder);
          return;
        }
        break;
      case 't':
        if ("type".equals(attributeName)) {
          readInType(in, builder);
          return;
        }
        break;
      default:
      }
      in.skipValue();
    }

    private void readInValue(JsonReader in, StopAfter.Builder builder)
        throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
      } else {
        Object value = valueTypeAdapter.read(in);
        builder.value(value);
      }
    }

    private void readInType(JsonReader in, StopAfter.Builder builder)
        throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
      } else {
        StopAfter.Type value = typeTypeAdapter.read(in);
        builder.type(value);
      }
    }
  }
}