Beispiel #1
0
 @Override
 public Locale read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   String locale = in.nextString();
   StringTokenizer tokenizer = new StringTokenizer(locale, "_");
   String language = null;
   String country = null;
   String variant = null;
   if (tokenizer.hasMoreElements()) {
     language = tokenizer.nextToken();
   }
   if (tokenizer.hasMoreElements()) {
     country = tokenizer.nextToken();
   }
   if (tokenizer.hasMoreElements()) {
     variant = tokenizer.nextToken();
   }
   if (country == null && variant == null) {
     return new Locale(language);
   } else if (variant == null) {
     return new Locale(language, country);
   } else {
     return new Locale(language, country, variant);
   }
 }
Beispiel #2
0
 @Override
 public Calendar read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   in.beginObject();
   int year = 0;
   int month = 0;
   int dayOfMonth = 0;
   int hourOfDay = 0;
   int minute = 0;
   int second = 0;
   while (in.peek() != JsonToken.END_OBJECT) {
     String name = in.nextName();
     int value = in.nextInt();
     if (YEAR.equals(name)) {
       year = value;
     } else if (MONTH.equals(name)) {
       month = value;
     } else if (DAY_OF_MONTH.equals(name)) {
       dayOfMonth = value;
     } else if (HOUR_OF_DAY.equals(name)) {
       hourOfDay = value;
     } else if (MINUTE.equals(name)) {
       minute = value;
     } else if (SECOND.equals(name)) {
       second = value;
     }
   }
   in.endObject();
   return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second);
 }
Beispiel #3
0
 public Number read(JsonReader jsonReader) throws IOException {
   if (jsonReader.peek() != JsonToken.NULL) {
     return Long.valueOf(jsonReader.nextLong());
   }
   jsonReader.nextNull();
   return null;
 }
Beispiel #4
0
 public T read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   return nameToConstant.get(in.nextString());
 }
Beispiel #5
0
 public Float read(JsonReader jsonReader) throws IOException {
   if (jsonReader.peek() != JsonToken.NULL) {
     return Float.valueOf((float) jsonReader.nextDouble());
   }
   jsonReader.nextNull();
   return null;
 }
    @Override
    public T read(JsonReader in) throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
      }

      T instance = constructor.construct();

      try {
        in.beginObject();
        while (in.hasNext()) {
          String name = in.nextName();
          BoundField field = boundFields.get(name);
          if (field == null || !field.deserialized) {
            in.skipValue();
          } else {
            field.read(in, instance);
          }
        }
      } catch (IllegalStateException e) {
        throw new JsonSyntaxException(e);
      } catch (IllegalAccessException e) {
        throw new AssertionError(e);
      }
      in.endObject();
      return instance;
    }
  @Override
  public Date read(JsonReader jsonReader) throws IOException {
    if (jsonReader.peek() == JsonToken.NULL) {
      jsonReader.nextNull();
      return null;
    }

    Date date = null;

    //        while(jsonReader.hasNext()) {
    if (jsonReader.peek().equals(JsonToken.BEGIN_OBJECT)) {
      jsonReader.beginObject();

      while (!jsonReader.peek().equals(JsonToken.END_OBJECT)) {
        JsonToken token = jsonReader.peek();
        switch (token) {
          case NAME:
            if (jsonReader.nextName().equals("$date")) {
              date = getDateFromString(jsonReader.nextString());
            }
            break;
          default:
            jsonReader.skipValue();
        }
      }
      jsonReader.endObject();
    }
    //      }

    return date;
  }
 private static String a(JsonReader paramJsonReader) {
   if (paramJsonReader.peek() == JsonToken.NULL) {
     paramJsonReader.nextNull();
     return null;
   }
   return paramJsonReader.nextString();
 }
 public Map<K, V> a(JsonReader paramJsonReader) throws IOException {
   Object localObject = paramJsonReader.peek();
   if (localObject == JsonToken.NULL) {
     paramJsonReader.nextNull();
     return null;
   }
   Map localMap = (Map) d.a();
   if (localObject == JsonToken.BEGIN_ARRAY) {
     paramJsonReader.beginArray();
     while (paramJsonReader.hasNext()) {
       paramJsonReader.beginArray();
       localObject = b.b(paramJsonReader);
       if (localMap.put(localObject, c.b(paramJsonReader)) != null) {
         throw new JsonSyntaxException("duplicate key: " + localObject);
       }
       paramJsonReader.endArray();
     }
     paramJsonReader.endArray();
     return localMap;
   }
   paramJsonReader.beginObject();
   while (paramJsonReader.hasNext()) {
     d.INSTANCE.promoteNameToValue(paramJsonReader);
     localObject = b.b(paramJsonReader);
     if (localMap.put(localObject, c.b(paramJsonReader)) != null) {
       throw new JsonSyntaxException("duplicate key: " + localObject);
     }
   }
   paramJsonReader.endObject();
   return localMap;
 }
Beispiel #10
0
    public BitSet read(JsonReader jsonreader)
    {
        JsonToken jsontoken;
        BitSet bitset;
        int i;
        if (jsonreader.peek() == JsonToken.NULL)
        {
            jsonreader.nextNull();
            return null;
        }
        bitset = new BitSet();
        jsonreader.beginArray();
        jsontoken = jsonreader.peek();
        i = 0;
_L2:
        boolean flag;
        if (jsontoken == JsonToken.END_ARRAY)
        {
            break MISSING_BLOCK_LABEL_209;
        }
        switch (..SwitchMap.com.google.gson.stream.JsonToken[jsontoken.ordinal()])
        {
        default:
            throw new JsonSyntaxException((new StringBuilder()).append("Invalid bitset value type: ").append(jsontoken).toString());

        case 2: // '\002'
            break; /* Loop/switch isn't completed */
Beispiel #11
0
 public Date read(JsonReader paramJsonReader) throws IOException {
   if (paramJsonReader.peek() == JsonToken.NULL) {
     paramJsonReader.nextNull();
     return null;
   }
   return deserializeToDate(paramJsonReader.nextString());
 }
Beispiel #12
0
 @Override
 public Number read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   return in.nextDouble();
 }
Beispiel #13
0
 @Override
 public Boolean read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   return Boolean.valueOf(in.nextString());
 }
Beispiel #14
0
 @Override
 public Date read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   return deserializeToDate(in.nextString());
 }
Beispiel #15
0
 public Object read(JsonReader jsonreader) {
   if (jsonreader.peek() == JsonToken.NULL) {
     jsonreader.nextNull();
     return null;
   } else {
     return a.read(jsonreader);
   }
 }
Beispiel #16
0
 @Override
 public StringBuffer read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   return new StringBuffer(in.nextString());
 }
Beispiel #17
0
 @Override
 public UUID read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   return java.util.UUID.fromString(in.nextString());
 }
Beispiel #18
0
 @Override
 public InetAddress read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   // regrettably, this should have included both the host name and the host address
   return InetAddress.getByName(in.nextString());
 }
Beispiel #19
0
 @Override
 public URL read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   String nextString = in.nextString();
   return "null".equals(nextString) ? null : new URL(nextString);
 }
Beispiel #20
0
 @Override
 public Class read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   } else {
     throw new UnsupportedOperationException(
         "Attempted to deserialize a java.lang.Class. Forgot to register a type adapter?");
   }
 }
 @Override
 public LocalDate read(JsonReader in) throws IOException {
   switch (in.peek()) {
     case NULL:
       in.nextNull();
       return null;
     default:
       String date = in.nextString();
       return formatter.parseLocalDate(date);
   }
 }
Beispiel #22
0
 @Override
 public Boolean read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   } else if (in.peek() == JsonToken.STRING) {
     // support strings for compatibility with GSON 1.7
     return Boolean.parseBoolean(in.nextString());
   }
   return in.nextBoolean();
 }
 private static Number a(JsonReader paramJsonReader) {
   if (paramJsonReader.peek() == JsonToken.NULL) {
     paramJsonReader.nextNull();
     return null;
   }
   try {
     long l = paramJsonReader.nextLong();
     return Long.valueOf(l);
   } catch (NumberFormatException paramJsonReader) {
     throw new JsonSyntaxException(paramJsonReader);
   }
 }
 @Override
 public Dependency read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   if (in.peek() != JsonToken.BEGIN_OBJECT) {
     in.nextString();
     return null;
   }
   return readDependency(in);
 }
Beispiel #25
0
 @Override
 public Number read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   try {
     return (short) in.nextInt();
   } catch (NumberFormatException e) {
     throw new JsonSyntaxException(e);
   }
 }
Beispiel #26
0
 @Override
 public Character read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   String str = in.nextString();
   if (str.length() != 1) {
     throw new JsonSyntaxException("Expecting character, got: " + str);
   }
   return str.charAt(0);
 }
Beispiel #27
0
 @Override
 public BigInteger read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   try {
     return new BigInteger(in.nextString());
   } catch (NumberFormatException e) {
     throw new JsonSyntaxException(e);
   }
 }
Beispiel #28
0
 @Override
 public Number read(JsonReader in) throws IOException {
   JsonToken jsonToken = in.peek();
   switch (jsonToken) {
     case NULL:
       in.nextNull();
       return null;
     case NUMBER:
       return new LazilyParsedNumber(in.nextString());
     default:
       throw new JsonSyntaxException("Expecting number, got: " + jsonToken);
   }
 }
Beispiel #29
0
 @Override
 public String read(JsonReader in) throws IOException {
   JsonToken peek = in.peek();
   if (peek == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   /* coerce booleans to strings for backwards compatibility */
   if (peek == JsonToken.BOOLEAN) {
     return Boolean.toString(in.nextBoolean());
   }
   return in.nextString();
 }
Beispiel #30
0
 @Override
 public URI read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   try {
     String nextString = in.nextString();
     return "null".equals(nextString) ? null : new URI(nextString);
   } catch (URISyntaxException e) {
     throw new JsonIOException(e);
   }
 }