当前位置: 首页>>代码示例>>Java>>正文


Java Gson.getDelegateAdapter方法代码示例

本文整理汇总了Java中com.google.gson.Gson.getDelegateAdapter方法的典型用法代码示例。如果您正苦于以下问题:Java Gson.getDelegateAdapter方法的具体用法?Java Gson.getDelegateAdapter怎么用?Java Gson.getDelegateAdapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gson.Gson的用法示例。


在下文中一共展示了Gson.getDelegateAdapter方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import com.google.gson.Gson; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    final TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);

    return new TypeAdapter<T>() {
        public void write(JsonWriter out, T value) throws IOException {
            delegate.write(out, value);
        }

        public T read(JsonReader in) throws IOException {
            T obj = delegate.read(in);
            if (obj instanceof PostProcessable) {
                ((PostProcessable) obj).postProcess();
            }
            return obj;
        }
    };
}
 
开发者ID:albertogiunta,项目名称:justintrain-client-android,代码行数:18,代码来源:PostProcessingEnabler.java

示例2: create

import com.google.gson.Gson; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    final TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);

    return new TypeAdapter<T>() {
        public void write(JsonWriter out, T value) throws IOException {
            delegate.write(out, value);
        }

        public T read(JsonReader in) throws IOException {
            T obj = delegate.read(in);
            if (obj instanceof PostProcessable) {
                ((PostProcessable)obj).postProcess();
            }
            return obj;
        }
    };
}
 
开发者ID:vpaliyX,项目名称:Last.fm-API,代码行数:18,代码来源:Adapter.java

示例3: create

import com.google.gson.Gson; //导入方法依赖的package包/类
@Override
public <T> TypeAdapter<T> create(final Gson gson, final TypeToken<T> tokenType) {
    final TypeAdapter<T> delegate = gson.getDelegateAdapter(this, tokenType);

    return new TypeAdapter<T>() {
        @Override
        public void write(JsonWriter out, T value) throws IOException {
            delegate.write(out, value);
        }

        @SuppressWarnings("unchecked")
        @Override
        public T read(JsonReader arg0) throws IOException {
            T t = delegate.read(arg0);
            if (List.class.isAssignableFrom(tokenType.getRawType())) {
                List<?> list = (List<?>) t;

                return (T) Collections.unmodifiableList(list);
            }

            return t;
        }
    };
}
 
开发者ID:pCloud,项目名称:pcloud-sdk-java,代码行数:25,代码来源:UnmodifiableListTypeFactory.java

示例4: create

import com.google.gson.Gson; //导入方法依赖的package包/类
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    final TypeAdapter<T> delegateAdapter = gson.getDelegateAdapter(this, type);
    final TypeAdapter<JsonElement> jsonElementAdapter = gson.getAdapter(JsonElement.class);

    return new TypeAdapter<T>() {
        @Override
        public void write(JsonWriter out, T value) throws IOException {
            delegateAdapter.write(out, value);
        }


        @Override
        @SuppressWarnings("PointlessBooleanExpression")
        public T read(JsonReader in) throws IOException {
            JsonElement jsonElement = jsonElementAdapter.read(in);
            if (jsonElement.isJsonObject()) {
                JsonObject jsonObject = jsonElement.getAsJsonObject();
                if (jsonObject.has(ERROR) && jsonObject.get(ERROR).getAsBoolean() == false) {
                    if (jsonObject.has(DATA) && isJson(jsonObject, DATA)) {
                        jsonElement = jsonObject.get(DATA);
                    }
                }
            }
            return delegateAdapter.fromJsonTree(jsonElement);
        }
    }.nullSafe();
}
 
开发者ID:drakeet,项目名称:rebase-android,代码行数:29,代码来源:ResponseTypeAdapterFactory.java

示例5: create

import com.google.gson.Gson; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(final Gson gson, final TypeToken<T> type) {
  Class<?> rawType = type.getRawType();
  final boolean skipSerialize = excludeClass(rawType, true);
  final boolean skipDeserialize = excludeClass(rawType, false);

  if (!skipSerialize && !skipDeserialize) {
    return null;
  }

  return new TypeAdapter<T>() {
    /** The delegate is lazily created because it may not be needed, and creating it may fail. */
    private TypeAdapter<T> delegate;

    @Override public T read(JsonReader in) throws IOException {
      if (skipDeserialize) {
        in.skipValue();
        return null;
      }
      return delegate().read(in);
    }

    @Override public void write(JsonWriter out, T value) throws IOException {
      if (skipSerialize) {
        out.nullValue();
        return;
      }
      delegate().write(out, value);
    }

    private TypeAdapter<T> delegate() {
      TypeAdapter<T> d = delegate;
      return d != null
          ? d
          : (delegate = gson.getDelegateAdapter(Excluder.this, type));
    }
  };
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:38,代码来源:Excluder.java

示例6: create

import com.google.gson.Gson; //导入方法依赖的package包/类
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    @SuppressWarnings("unchecked")
    Class<T> rawType = (Class<T>) type.getRawType();
    if (rawType != Post.class) {
        return null;
    }

    final TypeAdapter delegate = gson.getDelegateAdapter(this, type);
    //noinspection unchecked
    return (TypeAdapter<T>) new TypeAdapter<Post>() {
        @Override
        public void write(JsonWriter out, Post value) throws IOException {
            //noinspection unchecked
            delegate.write(out, value);
        }

        @Override
        public Post read(JsonReader in) throws IOException {
            Post post = (Post) delegate.read(in);

            // Empty posts imported from Ghost 0.11.x have mobiledoc == null, which is incorrect
            // but we do need to handle it. Drafts created in Ghost 1.0 on the other hand, do
            // have mobiledoc set to a valid, empty mobiledoc document.
            if (post.getMobiledoc() != null && !post.getMobiledoc().isEmpty()) {
                // Post JSON example:
                // {
                //   "mobiledoc": "{\"version\": \"0.3.1\", ... }",
                //   ...
                // }
                post.setMarkdown(GhostApiUtils.mobiledocToMarkdown(post.getMobiledoc()));
            } else {
                post.setMarkdown("");
            }
            return post;
        }
    };
}
 
开发者ID:TryGhost,项目名称:Ghost-Android,代码行数:39,代码来源:PostTypeAdapterFactory.java

示例7: create

import com.google.gson.Gson; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    Class<?> rawType = type.getRawType();
    final boolean skipSerialize = excludeClass(rawType, true);
    final boolean skipDeserialize = excludeClass(rawType, false);
    if (!skipSerialize && !skipDeserialize) {
        return null;
    }
    final Gson gson2 = gson;
    final TypeToken<T> typeToken = type;
    return new TypeAdapter<T>() {
        private TypeAdapter<T> delegate;

        public T read(JsonReader in) throws IOException {
            if (!skipDeserialize) {
                return delegate().read(in);
            }
            in.skipValue();
            return null;
        }

        public void write(JsonWriter out, T value) throws IOException {
            if (skipSerialize) {
                out.nullValue();
            } else {
                delegate().write(out, value);
            }
        }

        private TypeAdapter<T> delegate() {
            TypeAdapter<T> d = this.delegate;
            if (d != null) {
                return d;
            }
            d = gson2.getDelegateAdapter(Excluder.this, typeToken);
            this.delegate = d;
            return d;
        }
    };
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:40,代码来源:Excluder.java

示例8: create

import com.google.gson.Gson; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {

			final TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);
			Type classType = type.getType();
			if (classType == MutationSet.class) {
				return mutationSetAdapter(delegate);
			}
			else if (classType == GenePosition.class) {
				return genePositionAdapter(delegate);
			}
			return delegate;
		}
 
开发者ID:hivdb,项目名称:sierra,代码行数:13,代码来源:Json.java

示例9: create

import com.google.gson.Gson; //导入方法依赖的package包/类
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    final TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);
    final TypeAdapter<JsonElement> elementTypeAdapter = gson.getAdapter(JsonElement.class);


    return new TypeAdapter<T>() {
        @Override
        public void write(JsonWriter out, T value) throws IOException {
            delegate.write(out, value);
        }

        @Override
        public T read(JsonReader in) throws IOException {
            JsonElement jsonElement = elementTypeAdapter.read(in);
            if (jsonElement.isJsonObject()) {
                JsonObject jsonObject = jsonElement.getAsJsonObject();
                if (jsonObject.has("status")) {
                    int status = jsonObject.get("status").getAsInt();
                    String message = jsonObject.get("message").getAsString();
                    if (status == 0) {
                        //do nothing
                    } else {
                        throw new ApiException(status, message);
                    }
                }
                if (jsonObject.has(dataElementName)) {
                    jsonElement = jsonObject.get(dataElementName);
                }
            }
            return delegate.fromJsonTree(jsonElement);
        }

    }.nullSafe();
}
 
开发者ID:Lazyeraser,项目名称:DereHelper,代码行数:36,代码来源:ApiTypeAdapterFactory.java

示例10: create

import com.google.gson.Gson; //导入方法依赖的package包/类
@Override
public <T> TypeAdapter<T> create(final Gson gson, TypeToken<T> type) {
    final TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);
    return new MyTypeAdapter<T>(delegate, gson);
}
 
开发者ID:sap-nocops,项目名称:Jerkoff,代码行数:6,代码来源:ObjectTypeAdapterFactory.java


注:本文中的com.google.gson.Gson.getDelegateAdapter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。