Package com.google.gson

Examples of com.google.gson.JsonParseException


        @Override
        public NatRule deserialize(JsonElement jsonElement, Type type,
                JsonDeserializationContext context) throws JsonParseException {
            JsonObject jsonObject = jsonElement.getAsJsonObject();
            if (!jsonObject.has("type")) {
                throw new JsonParseException("Deserializing as a NatRule, but no type present in the json object");
            }

            String natRuleType = jsonObject.get("type").getAsString();
            if ("SourceNatRule".equals(natRuleType)) {
                return context.deserialize(jsonElement, SourceNatRule.class);
            }
            else if ("DestinationNatRule".equals(natRuleType)) {
                return context.deserialize(jsonElement, DestinationNatRule.class);
            }

            throw new JsonParseException("Failed to deserialize type \"" + natRuleType + "\"");
        }
View Full Code Here


      SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
      Date dt= null;
      try {
       dt = df.parse(json.getAsString());

      } catch(ParseException ex) { throw new JsonParseException("util.Date conversion failed");}
       return dt;
      }
View Full Code Here

       }
       else {
       return Key.create(clazz,Long.parseLong(element.getAsString()));
       }
        } catch (Exception e) {
         throw new JsonParseException("ObjectifKey conversion failed "+e.getMessage());
      }
    }     
View Full Code Here

            Object fieldValue = field.get(src);
            srcElement.add(fieldName, context.serialize(fieldValue));
         }
         return srcElement;
      } catch(Exception e) {
         throw new JsonParseException(e);
      }
   }
View Full Code Here

               Object fieldValue = field.get(src);
               srcElement.add(fieldName, context.serialize(fieldValue));
            }
            return srcElement;
         } catch(Exception e) {
            throw new JsonParseException(e);
         }
      }
View Full Code Here

               srcElement.add(fieldName, context.serialize(fieldValue));
            }
         }
         return srcElement;
      } catch(Exception e) {
         throw new JsonParseException(e);
      }
   }
View Full Code Here

      Stats statsObj = null;
     
      //First, check we have all our required fields ..
      for (String fieldName : requiredFields) {
        if (jsonObject.get(fieldName) == null) {
          throw new JsonParseException("Required Field Not Found: " + fieldName);
        }
      }
     
      statsObj = new Gson().fromJson(json, Stats.class);
View Full Code Here

        String date = json.getAsJsonPrimitive().getAsString();
        if (date == null || date.length() == 0) return null;
        SimpleDateFormat format = new SimpleDateFormat("MMM dd, yyyy hh:mm:ss a");
        return format.parse(date);
      } catch (ParseException e) {
        throw new JsonParseException(e.getMessage());
      }
    }
View Full Code Here

        opcode = object.get("opcode").getAsInt();
        owner = object.get("owner").getAsString();
        name = object.get("name").getAsString();
        desc = object.get("desc").getAsString();
        if(owner == null || name == null || desc == null)
            throw new JsonParseException("Could not parse FieldInsnNode");
        return new FieldInsnNode(opcode, owner, name, desc);
    }
View Full Code Here

    public HeaderField deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
      JsonObject jsonObject = json.getAsJsonObject();
      Set<Map.Entry<String, JsonElement>> entrySet = jsonObject.entrySet();
      if (entrySet.size() != 1) {
        throw new JsonParseException("JSON Object has multiple entries: " + entrySet);
      }
      Map.Entry<String, JsonElement> entry = entrySet.iterator().next();
      String name = entry.getKey();
      String value = entry.getValue().getAsString();
      return new HeaderField(name, value);
View Full Code Here

TOP

Related Classes of com.google.gson.JsonParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.