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


Java JsonReader.peek方法代码示例

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


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

示例1: fromJson

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
@Override
public Folder fromJson(JsonReader in) throws IOException {
    if (in.peek() == JsonReader.Token.NULL) {
        in.nextNull();
        return null;
    }
    Folder folder = new Folder();
    in.beginObject();
    while (in.hasNext()) {
        String name = in.nextName();
        switch (name) {
            case "id":
                folder.setId(in.nextLong());
                break;
            case "name":
                folder.setName(in.nextString());
                break;
            default:
                Log.w(TAG, "Unknown value in folder json: " + name);
                in.skipValue();
                break;
        }
    }
    in.endObject();
    return folder;
}
 
开发者ID:schaal,项目名称:ocreader,代码行数:27,代码来源:FolderTypeAdapter.java

示例2: enterPath

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
@Nullable
public static JsonReader enterPath(JsonReader reader, String path) throws IOException {
  try {
    if (reader.peek() != JsonReader.Token.BEGIN_OBJECT) return null;
  } catch (EOFException e) {
    return null;
  }
  reader.beginObject();
  while (reader.hasNext()) {
    if (reader.nextName().equals(path) && reader.peek() != JsonReader.Token.NULL) {
      return reader;
    } else {
      reader.skipValue();
    }
  }
  reader.endObject();
  return null;
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:19,代码来源:JsonReaders.java

示例3: fromJson

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
@Override
public User fromJson(JsonReader in) throws IOException {
    if (in.peek() == JsonReader.Token.NULL) {
        in.nextNull();
        return null;
    }
    User user = new User();
    in.beginObject();
    while (in.hasNext()) {
        String name = in.nextName();
        switch (name) {
            case "userId":
                user.setUserId(in.nextString());
                break;
            case "displayName":
                user.setDisplayName(in.nextString());
                break;
            case "lastLoginTimestamp":
                user.setLastLogin(new Date(in.nextLong() * 1000));
                break;
            case "avatar":
                if(in.peek() == JsonReader.Token.NULL)
                    in.skipValue();
                else
                    readAvatar(in, user, name);
                break;
            default:
                Log.w(TAG, "Unknown value in user json: " + name);
                in.skipValue();
                break;
        }
    }
    in.endObject();
    return user;
}
 
开发者ID:schaal,项目名称:ocreader,代码行数:36,代码来源:UserTypeAdapter.java

示例4: fromJson

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
@Override
public Status fromJson(JsonReader in) throws IOException {
    if (in.peek() == JsonReader.Token.NULL) {
        in.nextNull();
        return null;
    }

    final NullableJsonReader reader = new NullableJsonReader(in);
    final Status status = new Status();

    in.beginObject();

    while (in.hasNext()) {
        String name = in.nextName();
        switch (name) {
            case "version":
                status.setVersion(reader.nextString());
                break;
            case "warnings":
            case "issues":
                // this is called warnings in api v1-2, issues in api v2
                readWarnings(in, status);
                break;
            case "user":
                status.setUser(new UserTypeAdapter().fromJson(in));
                break;
            default:
                Log.w(TAG, "Unknown value in status json: " + name);
                in.skipValue();
                break;
        }
    }
    in.endObject();

    return status;
}
 
开发者ID:schaal,项目名称:ocreader,代码行数:37,代码来源:StatusTypeAdapter.java

示例5: visitNextOrSkip

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
static void visitNextOrSkip(JsonReader reader, String name, Set<String> result)
    throws IOException {
  switch (reader.peek()) {
    case BEGIN_ARRAY:
      reader.beginArray();
      while (reader.hasNext()) visitObject(reader, name, result);
      reader.endArray();
      break;
    case BEGIN_OBJECT:
      visitObject(reader, name, result);
      break;
    default:
      reader.skipValue();
  }
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:16,代码来源:JsonReaders.java

示例6: nextNullableString

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
public static String nextNullableString(JsonReader reader) throws IOException {
    if (reader.peek() == JsonReader.Token.NULL) {
        reader.skipValue();
        return null;
    } else {
        return reader.nextString();
    }
}
 
开发者ID:kamikat,项目名称:moshi-jsonapi,代码行数:9,代码来源:MoshiHelper.java

示例7: nextNullableObject

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
public static <T> T nextNullableObject(JsonReader reader, JsonAdapter<T> adapter) throws IOException {
    if (reader.peek() == JsonReader.Token.NULL) {
        reader.skipValue();
        return null;
    } else {
        return adapter.fromJson(reader);
    }
}
 
开发者ID:kamikat,项目名称:moshi-jsonapi,代码行数:9,代码来源:MoshiHelper.java

示例8: fromJson

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
@Override public T fromJson(JsonReader reader) throws IOException {
  if (reader.peek() == JsonReader.Token.NULL) {
    reader.nextNull(); // We need to consume the value.
    return fallback;
  }
  return delegate.fromJson(reader);
}
 
开发者ID:serj-lotutovici,项目名称:moshi-lazy-adapters,代码行数:8,代码来源:FallbackOnNullJsonAdapter.java

示例9: fromJson

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
@Override
public T fromJson(JsonReader reader) throws IOException {
    if (reader.peek() == JsonReader.Token.BOOLEAN) {
        if (reader.nextBoolean()) {
            throw new IllegalStateException("Expected false or object.");
        }
        return null;
    }
    return delegate.fromJson(reader);
}
 
开发者ID:biafra23,项目名称:EtherWallet,代码行数:11,代码来源:FalseToNullFactory.java

示例10: fromJson

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
@Override
public Set<T> fromJson(final JsonReader reader) throws IOException {
    final EnumSet<T> result = EnumSet.noneOf(enumType);
    final JsonReader.Token nextToken = reader.peek();
    final List<String> parts;

    if (nextToken == JsonReader.Token.BEGIN_ARRAY) {
        parts = new ArrayList<>();

        reader.beginArray();
        while (reader.hasNext()) {
            parts.add(reader.nextString());
        }
        reader.endArray();
    } else if (nextToken == JsonReader.Token.NULL) {
        reader.nextNull();

        parts = Collections.emptyList();
    } else {
        parts = Arrays.asList(reader.nextString().split(delimiter));
    }

    for (final String part : parts) {
        for (final Field field : enumType.getFields()) {
            Json annotation = field.getAnnotation(Json.class);

            if (annotation != null && annotation.name().equalsIgnoreCase(part)) {
                result.add(Enum.valueOf(enumType, field.getName()));

                break;
            }
        }
    }

    return result;
}
 
开发者ID:proxer,项目名称:ProxerLibJava,代码行数:37,代码来源:DelimitedEnumSetAdapterFactory.java

示例11: fromJson

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
@Override
public Feed fromJson(JsonReader in) throws IOException {
    if (in.peek() == JsonReader.Token.NULL) {
        in.nextNull();
        return null;
    }

    final NullableJsonReader reader = new NullableJsonReader(in);

    final Feed feed = new Feed();

    in.beginObject();

    while (in.hasNext()) {
        String name = in.nextName();
        switch (name) {
            case "id":
                feed.setId(in.nextLong());
                break;
            case "url":
                feed.setUrl(reader.nextString());
                break;
            case "link":
                feed.setLink(reader.nextString());
                break;
            case "faviconLink":
                String faviconLink = reader.nextString();
                if (faviconLink != null && TextUtils.getTrimmedLength(faviconLink) == 0)
                    faviconLink = null;
                feed.setFaviconLink(faviconLink);
                break;
            // title in API v1-2, name in API v2
            case "title":
            case "name":
                feed.setName(StringUtils.cleanString(in.nextString()));
                break;
            case "added":
                in.skipValue();
                break;
            case "folderId":
                feed.setFolderId(in.nextLong());
                break;
            case "unreadCount":
                // skip unreadCount, calculated later in SyncService
                in.skipValue();
                break;
            case "ordering":
                // createFeed returns a feed with ordering set to NULL
                feed.setOrdering(reader.nextInt(0));
                break;
            case "pinned":
                // createFeed returns a feed with pinned set to NULL
                feed.setPinned(reader.nextBoolean(false));
                break;
            case "updateErrorCount":
                feed.setUpdateErrorCount(reader.nextInt(0));
                break;
            case "lastUpdateError":
                feed.setLastUpdateError(reader.nextString());
                break;
            case "error":
                parseError(reader, feed);
                break;
            default:
                Log.w(TAG, "Unknown value in feed json: " + name);
                in.skipValue();
                break;
        }
    }
    in.endObject();
    return feed;
}
 
开发者ID:schaal,项目名称:ocreader,代码行数:73,代码来源:FeedTypeAdapter.java

示例12: fromJson

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
@Override
public Span fromJson(JsonReader reader) throws IOException {
  Span.Builder result = Span.builder();
  reader.beginObject();
  while (reader.hasNext()) {
    String nextName = reader.nextName();
    if (reader.peek() == JsonReader.Token.NULL) {
      reader.skipValue();
      continue;
    }
    switch (nextName) {
      case "traceId":
        String traceId = reader.nextString();
        if (traceId.length() == 32) {
          result.traceIdHigh(lowerHexToUnsignedLong(traceId, 0));
        }
        result.traceId(lowerHexToUnsignedLong(traceId));
        break;
      case "name":
        result.name(reader.nextString());
        break;
      case "id":
        result.id(Util.lowerHexToUnsignedLong(reader.nextString()));
        break;
      case "parentId":
        result.parentId(Util.lowerHexToUnsignedLong(reader.nextString()));
        break;
      case "timestamp":
        result.timestamp(reader.nextLong());
        break;
      case "duration":
        result.duration(reader.nextLong());
        break;
      case "annotations":
        reader.beginArray();
        while (reader.hasNext()) {
          result.addAnnotation(ANNOTATION_ADAPTER.fromJson(reader));
        }
        reader.endArray();
        break;
      case "binaryAnnotations":
        reader.beginArray();
        while (reader.hasNext()) {
          result.addBinaryAnnotation(BINARY_ANNOTATION_ADAPTER.fromJson(reader));
        }
        reader.endArray();
        break;
      case "debug":
        result.debug(reader.nextBoolean());
        break;
      default:
        reader.skipValue();
    }
  }
  reader.endObject();
  return result.build();
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:58,代码来源:ZipkinAdapters.java

示例13: dump

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
public static void dump(JsonReader reader, JsonWriter writer) throws IOException {
    int nested = 0;
    boolean nullFlag = writer.getSerializeNulls();
    writer.setSerializeNulls(true);
    try {
        while (reader.peek() != JsonReader.Token.END_DOCUMENT) {
            switch (reader.peek()) {
                case BEGIN_ARRAY:
                    nested++;
                    reader.beginArray();
                    writer.beginArray();
                    break;
                case END_ARRAY:
                    reader.endArray();
                    writer.endArray();
                    if (0 == --nested) return;
                    break;
                case BEGIN_OBJECT:
                    nested++;
                    reader.beginObject();
                    writer.beginObject();
                    break;
                case END_OBJECT:
                    reader.endObject();
                    writer.endObject();
                    if (0 == --nested) return;
                    break;
                case NAME:
                    writer.name(reader.nextName());
                    break;
                case NUMBER:
                    try {
                        writer.value(reader.nextLong());
                    } catch (Exception ignored) {
                        writer.value(reader.nextDouble());
                    }
                    break;
                case BOOLEAN:
                    writer.value(reader.nextBoolean());
                    break;
                case STRING:
                    writer.value(reader.nextString());
                    break;
                case NULL:
                    reader.nextNull();
                    writer.nullValue();
                    break;
            }
        }
    } finally {
        writer.setSerializeNulls(nullFlag);
    }
}
 
开发者ID:kamikat,项目名称:moshi-jsonapi,代码行数:54,代码来源:MoshiHelper.java

示例14: fromJson

import com.squareup.moshi.JsonReader; //导入方法依赖的package包/类
/**
 * Recursively goes through the json and finds the given root. Returns the object wrapped by the
 * provided {@code path}.
 */
private static <T> T fromJson(JsonAdapter<T> adapter, JsonReader reader, String[] path,
    int index, boolean failOnNotFound) throws IOException {
  if (index == path.length) {
    //noinspection unchecked This puts full responsibility on the caller.
    return adapter.fromJson(reader);
  } else {
    reader.beginObject();
    Exception caughtException = null;
    try {
      String root = path[index];
      while (reader.hasNext()) {
        if (reader.nextName().equals(root)) {
          if (reader.peek() == JsonReader.Token.NULL) {
            // Consumer expects a value, not a null.
            if (failOnNotFound) {
              throw new JsonDataException(String.format(
                  "Wrapped Json expected at path: %s. Found null at %s",
                  Arrays.asList(path), reader.getPath()
              ));
            }

            return reader.nextNull();
          }
          return fromJson(adapter, reader, path, ++index, failOnNotFound);
        } else {
          reader.skipValue();
        }
      }
    } catch (Exception e) {
      caughtException = e;
    } finally {
      // If the try block throw an exception, rethrow it up the stack.
      if (caughtException instanceof IOException) {
        //noinspection ThrowFromFinallyBlock
        throw (IOException) caughtException;
      } else if (caughtException instanceof JsonDataException) {
        //noinspection ThrowFromFinallyBlock
        throw (JsonDataException) caughtException;
      } else if (caughtException != null) {
        //noinspection ThrowFromFinallyBlock
        throw new AssertionError(caughtException);
      }
      // If the json has an additional key, that was not red, we ignore it.
      while (reader.hasNext()) {
        reader.skipValue();
      }
      // End object, so that other adapters (if any) can proceed.
      reader.endObject();
    }
    throw new JsonDataException(String.format(
        "Wrapped Json expected at path: %s. Actual: %s",
        Arrays.asList(path), reader.getPath()));
  }
}
 
开发者ID:serj-lotutovici,项目名称:moshi-lazy-adapters,代码行数:59,代码来源:WrappedJsonAdapter.java


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