Java Code Examples for org.codehaus.jackson.JsonParser#getIntValue()
The following examples show how to use
org.codehaus.jackson.JsonParser#getIntValue() .
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: JsonSerdeUtils.java From incubator-hivemall with Apache License 2.0 | 6 votes |
@Nonnull private static Object parseValue(@Nonnull final JsonParser p) throws JsonParseException, IOException { final JsonToken t = p.getCurrentToken(); switch (t) { case VALUE_FALSE: return Boolean.FALSE; case VALUE_TRUE: return Boolean.TRUE; case VALUE_NULL: return null; case VALUE_STRING: return p.getText(); case VALUE_NUMBER_FLOAT: return p.getDoubleValue(); case VALUE_NUMBER_INT: return p.getIntValue(); default: throw new IOException("Unexpected token: " + t); } }
Example 2
Source File: BackendResponse.java From ReactiveLab with Apache License 2.0 | 4 votes |
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 |
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(); } }