當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。