Java Code Examples for org.codehaus.jackson.JsonParser#getLongValue()

The following examples show how to use org.codehaus.jackson.JsonParser#getLongValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientObjectMapper.java    From hraven with Apache License 2.0 6 votes vote down vote up
@Override
public CounterMap deserialize(JsonParser jsonParser,
                              DeserializationContext deserializationContext)
                              throws IOException {
  CounterMap counterMap = new CounterMap();

  JsonToken token;
  while ((token = jsonParser.nextToken()) != JsonToken.END_OBJECT) {
    assertToken(token, JsonToken.FIELD_NAME);
    String group = jsonParser.getCurrentName();

    assertToken(jsonParser.nextToken(), JsonToken.START_OBJECT);
    while ((token = jsonParser.nextToken()) != JsonToken.END_OBJECT) {
      if (token != JsonToken.VALUE_NUMBER_INT) {
        continue; // all deserialized values are ints
      }

      Counter counter =
          new Counter(group, jsonParser.getCurrentName(), jsonParser.getLongValue());
      counterMap.add(counter);
    }
  }
  return counterMap;
}
 
Example 2
Source File: BackendResponse.java    From ReactiveLab with Apache License 2.0 4 votes vote down vote up
private static BackendResponse parseBackendResponse(JsonParser parser) throws IOException {
    try {
        // Sanity check: verify that we got "Json Object":
        if (parser.nextToken() != JsonToken.START_OBJECT) {
            throw new IOException("Expected data to start with an Object");
        }
        long responseKey = 0;
        int delay = 0;
        int numItems = 0;
        int itemSize = 0;
        String[] items = null;
        JsonToken current;

        while (parser.nextToken() != JsonToken.END_OBJECT) {
            String fieldName = parser.getCurrentName();
            // advance
            current = parser.nextToken();
            if (fieldName.equals("responseKey")) {
                responseKey = parser.getLongValue();
            } else if (fieldName.equals("delay")) {
                delay = parser.getIntValue();
            } else if (fieldName.equals("itemSize")) {
                itemSize = parser.getIntValue();
            } else if (fieldName.equals("numItems")) {
                numItems = parser.getIntValue();
            } else if (fieldName.equals("items")) {
                // expect numItems to be populated before hitting this
                if (numItems == 0) {
                    throw new IllegalStateException("Expected numItems > 0");
                }
                items = new String[numItems];
                if (current == JsonToken.START_ARRAY) {
                    int j = 0;
                    // For each of the records in the array
                    while (parser.nextToken() != JsonToken.END_ARRAY) {
                        items[j++] = parser.getText();
                    }
                } else {
                    //                            System.out.println("Error: items should be an array: skipping.");
                    parser.skipChildren();
                }

            }
        }
        return new BackendResponse(responseKey, delay, numItems, itemSize, items);
    } finally {
        parser.close();
    }
}
 
Example 3
Source File: BackendResponse.java    From WSPerfLab with Apache License 2.0 4 votes vote down vote up
public static BackendResponse parseBackendResponse(JsonParser parser) throws IOException {
    try {
        // Sanity check: verify that we got "Json Object":
        if (parser.nextToken() != JsonToken.START_OBJECT) {
            throw new IOException("Expected data to start with an Object");
        }
        long responseKey = 0;
        int delay = 0;
        int numItems = 0;
        int itemSize = 0;
        String[] items = null;
        JsonToken current;

        while (parser.nextToken() != JsonToken.END_OBJECT) {
            String fieldName = parser.getCurrentName();
            // advance
            current = parser.nextToken();
            if (fieldName.equals("responseKey")) {
                responseKey = parser.getLongValue();
            } else if (fieldName.equals("delay")) {
                delay = parser.getIntValue();
            } else if (fieldName.equals("itemSize")) {
                itemSize = parser.getIntValue();
            } else if (fieldName.equals("numItems")) {
                numItems = parser.getIntValue();
            } else if (fieldName.equals("items")) {
                // expect numItems to be populated before hitting this
                if (numItems == 0) {
                    throw new IllegalStateException("Expected numItems > 0");
                }
                items = new String[numItems];
                if (current == JsonToken.START_ARRAY) {
                    int j = 0;
                    // For each of the records in the array
                    while (parser.nextToken() != JsonToken.END_ARRAY) {
                        items[j++] = parser.getText();
                    }
                } else {
                    //                            System.out.println("Error: items should be an array: skipping.");
                    parser.skipChildren();
                }

            }
        }
        
        return new BackendResponse(responseKey, delay, numItems, itemSize, items);
    } finally {
        parser.close();
    }
}