Code example for JsonReader

Methods: nextNullpeek

  public static final TypeAdapterFactory URI_FACTORY = newFactory(URI.class, URI);
  public static final TypeAdapter<InetAddress> INET_ADDRESS = new TypeAdapter<InetAddress>() {
    public InetAddress read(JsonReader in) throws IOException { 
      if (in.peek() == JsonToken.NULL) { 
        return null; 
      // regrettably, this should have included both the host name and the host address 
      return InetAddress.getByName(in.nextString()); 
    public void write(JsonWriter out, InetAddress value) throws IOException { 
      out.value(value == null ? null : value.getHostAddress()); 
  public static final TypeAdapterFactory INET_ADDRESS_FACTORY =
    newTypeHierarchyFactory(InetAddress.class, INET_ADDRESS);