Esempio n. 1
0
 @Override
 public Student read(JsonReader reader) throws IOException {
   Student student = new Student();
   reader.beginObject();
   String fieldname = null;
   while (reader.hasNext()) {
     JsonToken token = reader.peek();
     if (token.equals(JsonToken.NAME)) {
       // get the current token
       fieldname = reader.nextName();
     }
     if ("name".equals(fieldname)) {
       // move to next token
       token = reader.peek();
       student.setName(reader.nextString());
     }
     if ("rollNo".equals(fieldname)) {
       // move to next token
       token = reader.peek();
       student.setRollNo(reader.nextInt());
     }
   }
   reader.endObject();
   return student;
 }
Esempio n. 2
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 */
Esempio n. 3
0
 private String nextValue() {
   try {
     tokenType = jsonReader.peek();
     JsonObject peek = stackObj.peek();
     String valueType = peek.getValueType();
     if (!validateArgumentTypes(tokenType, valueType)) {
       log.error(
           "Value type miss match, Expected value type - '"
               + valueType
               + "', but found - '"
               + tokenType.toString()
               + "'");
       throw new IllegalArgumentException(
           "Value type miss match, Expected value type - '"
               + valueType
               + "', but found - '"
               + tokenType.toString()
               + "'");
     }
     if (tokenType == JsonToken.STRING) {
       value = jsonReader.nextString();
     } else if (tokenType == JsonToken.BOOLEAN) {
       value = String.valueOf(jsonReader.nextBoolean());
     } else if (tokenType == JsonToken.NUMBER) {
       if (valueType.equals("int")) {
         value = String.valueOf(jsonReader.nextInt());
       } else if (valueType.equals("long")) {
         value = String.valueOf(jsonReader.nextLong());
       } else if (valueType.equals("double")) {
         value = String.valueOf(jsonReader.nextDouble());
       } else if (valueType.equals("float")) {
         value = String.valueOf(jsonReader.nextDouble());
       }
     } else if (tokenType == JsonToken.NULL) {
       jsonReader.nextNull();
       value = null;
     } else {
       log.error("Couldn't read the value, Illegal state exception");
       throw new RuntimeException("Couldn't read the value, Illegal state exception");
     }
   } catch (IOException e) {
     log.error("IO error while reading json stream");
     throw new RuntimeException("IO error while reading json stream");
   }
   return value;
 }
    public Number read(JsonReader jsonreader)
    {
        JsonToken jsontoken = jsonreader.peek();
        switch (.SwitchMap.com.google.gson.stream.JsonToken[jsontoken.ordinal()])
        {
        case 2: // '\002'
        case 3: // '\003'
        default:
            throw new JsonSyntaxException((new StringBuilder()).append("Expecting number, got: ").append(jsontoken).toString());

        case 4: // '\004'
            jsonreader.nextNull();
            return null;

        case 1: // '\001'
            return new LazilyParsedNumber(jsonreader.nextString());
        }
    }
Esempio n. 5
0
 /**
  * this method is to check whether input json type matches with the types specified in the schema
  *
  * @param tokenType
  * @param expectedType
  * @return true if it matches false otherwise
  */
 private boolean validateArgumentTypes(JsonToken tokenType, String expectedType) {
   if (expectedType.equalsIgnoreCase(tokenType.toString())) {
     return true;
   } else if (tokenType == JsonToken.NULL) {
     return true;
   } else if (tokenType == JsonToken.NUMBER) {
     if (expectedType.equals("int")
         || expectedType.equals("long")
         || expectedType.equals("double")
         || expectedType.equals("float")) {
       return true;
     }
   }
   return false;
 }