Examples of TypeAdapter


Examples of com.google.gson.TypeAdapter

  {
    Object localObject = this.delegate;
    Type localType = getRuntimeTypeIfMoreSpecific(this.type, paramObject);
    if (localType != this.type)
    {
      TypeAdapter localTypeAdapter = this.context.getAdapter(TypeToken.get(localType));
      if (!(localTypeAdapter instanceof ReflectiveTypeAdapterFactory.Adapter))
        localObject = localTypeAdapter;
      else if (!(this.delegate instanceof ReflectiveTypeAdapterFactory.Adapter))
        localObject = this.delegate;
      else
View Full Code Here

Examples of com.google.gson.TypeAdapter

    Class localClass = paramTypeToken.getRawType();
    final boolean bool1 = excludeClass(localClass, true);
    final boolean bool2 = excludeClass(localClass, false);
    if ((!bool1) && (!bool2))
      return null;
    return new TypeAdapter()
    {
      private TypeAdapter delegate;

      public Object read(JsonReader paramAnonymousJsonReader)
        throws IOException
      {
        if (bool2)
        {
          paramAnonymousJsonReader.skipValue();
          return null;
        }
        return delegate().read(paramAnonymousJsonReader);
      }

      public void write(JsonWriter paramAnonymousJsonWriter, Object paramAnonymousObject)
        throws IOException
      {
        if (bool1)
        {
          paramAnonymousJsonWriter.nullValue();
          return;
        }
        delegate().write(paramAnonymousJsonWriter, paramAnonymousObject);
      }

      private TypeAdapter delegate()
      {
        TypeAdapter localTypeAdapter = this.delegate;
        return this.delegate = paramGson.getDelegateAdapter(Excluder.this, paramTypeToken);
      }
    };
  }
View Full Code Here

Examples of com.google.gson.TypeAdapter

    if (paramObject == null)
    {
      paramJsonWriter.nullValue();
      return;
    }
    TypeAdapter localTypeAdapter = this.gson.getAdapter(paramObject.getClass());
    if ((localTypeAdapter instanceof ObjectTypeAdapter))
    {
      paramJsonWriter.beginObject();
      paramJsonWriter.endObject();
      return;
    }
    localTypeAdapter.write(paramJsonWriter, paramObject);
  }
View Full Code Here

Examples of com.google.gson.TypeAdapter

    Type localType1 = paramTypeToken.getType();
    Class localClass = paramTypeToken.getRawType();
    if (!Collection.class.isAssignableFrom(localClass))
      return null;
    Type localType2 = $Gson.Types.getCollectionElementType(localType1, localClass);
    TypeAdapter localTypeAdapter = paramGson.getAdapter(TypeToken.get(localType2));
    ObjectConstructor localObjectConstructor = this.constructorConstructor.get(paramTypeToken);
    Adapter localAdapter = new Adapter(paramGson, localType2, localTypeAdapter, localObjectConstructor);
    return localAdapter;
  }
View Full Code Here

Examples of com.google.gson.TypeAdapter

    return (TypeAdapter<T>) create(gson);
  }

  @SuppressWarnings({"rawtypes", "unchecked"})
  private TypeAdapter<ContentBody> create(final Gson gson) {
    final TypeAdapter simpleBodyAdapter = gson.getAdapter(TypeToken.get(spec.getSimpleBodyType()));
    switch(spec.getContentBodyType()) {
      case SIMPLE:
        return new TypeAdapter<ContentBody>() {
          @Override
          public ContentBody read(JsonReader reader) throws IOException {
            return createBuilder()
                .setSimpleBody(simpleBodyAdapter.read(reader))
                .build();
          }
          public void write(JsonWriter writer, ContentBody value) throws IOException {
            ContentBody src = (ContentBody) value;
            simpleBodyAdapter.write(writer, src.getSimpleBody());
          }
        };
      case LIST:
        return new TypeAdapter<ContentBody>() {
          @Override
          public ContentBody read(JsonReader reader) throws IOException {
            ContentBody.Builder builder = createBuilder();
            reader.beginArray();
            while (reader.hasNext()) {
              builder.addToListBody(simpleBodyAdapter.read(reader));
            }
            reader.endArray();
            return (ContentBody) builder.build();
          }
          @Override
          public void write(JsonWriter writer, ContentBody value) throws IOException {
            ContentBody src = (ContentBody) value;
            writer.beginArray();
            for(Object entry : src.getListBody()) {
              simpleBodyAdapter.write(writer, entry);
            }
            writer.endArray();
          }
        };
      case MAP:
        return new TypeAdapter<ContentBody>() {
          private final LazyAdapterMap adapters = new LazyAdapterMap(gson, spec);
          @Override
          public ContentBody read(JsonReader reader) throws IOException {
            ContentBody.Builder builder = createBuilder();
            reader.beginObject();
            while (reader.hasNext()) {
              String key = reader.nextName();
              TypeAdapter adapter = adapters.getAdapter(key);
              Object value = adapter.read(reader);
              builder.put(key, value);
            }
            reader.endObject();
            return (CB) builder.build();
          }
          @Override
          public void write(JsonWriter writer, ContentBody value) throws IOException {
            ContentBody src = (ContentBody) value;
            writer.beginObject();
            for(Map.Entry<String, Object> entry : src.entrySet()) {
              String key = entry.getKey();
              TypeAdapter adapter = adapters.getAdapter(key);
              writer.name(key);
              adapter.write(writer, entry.getValue());
            }
            writer.endObject();
          }
        };
      default:
View Full Code Here

Examples of com.google.gson.TypeAdapter

    LazyAdapterMap(Gson gson, ContentBodySpec spec) {
      this.gson = gson;
      this.spec = spec;
    }
    TypeAdapter getAdapter(String paramName) {
      TypeAdapter adapter = map.get(paramName);
      if (adapter == null) {
        Type entryType = spec.getTypeFor(paramName);
        adapter = gson.getAdapter(TypeToken.get(entryType));
        map.put(paramName, adapter);
      }
View Full Code Here

Examples of com.massivecraft.mcore.xlib.gson.TypeAdapter

      final TypeAdapter<?> typeAdapter = context.getAdapter(fieldType);
      @SuppressWarnings({"unchecked", "rawtypes"}) // the type adapter and field type always agree
      @Override void write(JsonWriter writer, Object value)
          throws IOException, IllegalAccessException {
        Object fieldValue = field.get(value);
        TypeAdapter t =
          new TypeAdapterRuntimeTypeWrapper(context, this.typeAdapter, fieldType.getType());
        t.write(writer, fieldValue);
      }
      @Override void read(JsonReader reader, Object value)
          throws IOException, IllegalAccessException {
        Object fieldValue = typeAdapter.read(reader);
        if (fieldValue != null || !isPrimitive) {
View Full Code Here

Examples of com.massivecraft.mcore.xlib.gson.TypeAdapter

    // First preference: a type adapter registered for the runtime type
    // Second preference: a type adapter registered for the declared type
    // Third preference: reflective type adapter for the runtime type (if it is a sub class of the declared type)
    // Fourth preference: reflective type adapter for the declared type

    TypeAdapter chosen = delegate;
    Type runtimeType = getRuntimeTypeIfMoreSpecific(type, value);
    if (runtimeType != type) {
      TypeAdapter runtimeTypeAdapter = context.getAdapter(TypeToken.get(runtimeType));
      if (!(runtimeTypeAdapter instanceof ReflectiveTypeAdapterFactory.Adapter)) {
        // The user registered a type adapter for the runtime type, so we will use that
        chosen = runtimeTypeAdapter;
      } else if (!(delegate instanceof ReflectiveTypeAdapterFactory.Adapter)) {
        // The user registered a type adapter for Base class, so we prefer it over the
View Full Code Here

Examples of fit.TypeAdapter

  public static boolean callEqualsMethod(Class<?> type, Object o1, Object o2)
  throws Exception
  {
    boolean result = false;

    TypeAdapter ta = TypeAdapter.adapterFor(type);
    if (ta != null &&
        !ta.getClass().equals(fit.TypeAdapter.class))
    {
      result = ta.equals(o1, ta.parse(o2.toString()));
    }
    else
    {
      Method m = type.getMethod("equals",
          new Class[] {Object.class});
View Full Code Here

Examples of fit.TypeAdapter

      // is it a static class.field?
      Object ret = getStaticField(parameter);
      if (ret != null)
        return ret;

      TypeAdapter ta = TypeAdapter.adapterFor(paramType);
      //debug(paramType + " Parameter: [" + parameter + "] " + ta.getClass());
      if (ta != null &&
          !ta.getClass().equals(fit.TypeAdapter.class)
      )
      {
        //debug("Inside Parameter: [" + parameter + "] " + ta.getClass());
        try
        {
          if (paramType.isArray() && parameter.startsWith(ARRAY))
          {
            ta.init(this, paramType);
            Class<?> componentType = paramType.getComponentType();
            TypeAdapter cta = TypeAdapter.on(this, componentType);
            //debug(cta + " - componentType: " + componentType.getCanonicalName());

            String[] arrStr = parameter.substring(ARRAY.length()).split(",");
            paramObject = Array.newInstance(componentType, arrStr.length);
            for (int i=0; i < arrStr.length; i++) {
              String token = arrStr[i].trim();
              Object var = fetchVariable(token);
              if (var == null) {
                var = cta.parse(token);
                //debug(var + " - i: " + i + " - " + token);
              }
              Array.set(paramObject, i, var);
            }
          }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.