Example usage for com.fasterxml.jackson.core JsonToken VALUE_NUMBER_FLOAT

List of usage examples for com.fasterxml.jackson.core JsonToken VALUE_NUMBER_FLOAT

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonToken VALUE_NUMBER_FLOAT.

Prototype

JsonToken VALUE_NUMBER_FLOAT

To view the source code for com.fasterxml.jackson.core JsonToken VALUE_NUMBER_FLOAT.

Click Source Link

Document

VALUE_NUMBER_INT is returned when a numeric token other that is not an integer is encountered: that is, a number that does have floating point or exponent marker in it, in addition to one or more digits.

Usage

From source file:org.wso2.extension.siddhi.map.json.sourcemapper.JsonSourceMapper.java

private Event convertToSingleEventForDefaultMapping(Object eventObject) throws IOException {
    Event event = new Event(attributesSize);
    Object[] data = event.getData();
    JsonParser parser;//from www .j a v a2  s  .  c om
    int numberOfProvidedAttributes = 0;
    try {
        parser = factory.createParser(eventObject.toString());
    } catch (IOException e) {
        throw new SiddhiAppRuntimeException(
                "Initializing a parser failed for the event string." + eventObject.toString());
    }
    int position;
    while (!parser.isClosed()) {
        JsonToken jsonToken = parser.nextToken();
        if (JsonToken.START_OBJECT.equals(jsonToken)) {
            parser.nextToken();
            if (DEFAULT_JSON_EVENT_IDENTIFIER.equalsIgnoreCase(parser.getText())) {
                parser.nextToken();
            } else {
                log.error("Default json message " + eventObject
                        + " contains an invalid event identifier. Required \"event\", " + "but found \""
                        + parser.getText() + "\". Hence dropping the message.");
                return null;
            }
        } else if (JsonToken.FIELD_NAME.equals(jsonToken)) {
            String key = parser.getCurrentName();
            numberOfProvidedAttributes++;
            position = findDefaultMappingPosition(key);
            if (position == -1) {
                log.error("Stream \"" + streamDefinition.getId() + "\" does not have an attribute named \""
                        + key + "\", but the received event " + eventObject.toString()
                        + " does. Hence dropping the message.");
                return null;
            }
            jsonToken = parser.nextToken();
            Attribute.Type type = streamAttributes.get(position).getType();

            if (JsonToken.VALUE_NULL.equals(jsonToken)) {
                data[position] = null;
            } else {
                switch (type) {
                case BOOL:
                    if (JsonToken.VALUE_TRUE.equals(jsonToken) || JsonToken.VALUE_FALSE.equals(jsonToken)) {
                        data[position] = parser.getValueAsBoolean();
                    } else {
                        log.error("Json message " + eventObject.toString()
                                + " contains incompatible attribute types and values. Value " + parser.getText()
                                + " is not compatible with type BOOL. " + "Hence dropping the message.");
                        return null;
                    }
                    break;
                case INT:
                    if (JsonToken.VALUE_NUMBER_INT.equals(jsonToken)) {
                        data[position] = parser.getValueAsInt();
                    } else {
                        log.error("Json message " + eventObject.toString()
                                + " contains incompatible attribute types and values. Value " + parser.getText()
                                + " is not compatible with type INT. " + "Hence dropping the message.");
                        return null;
                    }
                    break;
                case DOUBLE:
                    if (JsonToken.VALUE_NUMBER_FLOAT.equals(jsonToken)) {
                        data[position] = parser.getValueAsDouble();
                    } else {
                        log.error("Json message " + eventObject.toString()
                                + " contains incompatible attribute types and values. Value " + parser.getText()
                                + " is not compatible with type DOUBLE. " + "Hence dropping the message.");
                        return null;
                    }
                    break;
                case STRING:
                    if (JsonToken.VALUE_STRING.equals(jsonToken)) {
                        data[position] = parser.getValueAsString();
                    } else {
                        log.error("Json message " + eventObject.toString()
                                + " contains incompatible attribute types and values. Value " + parser.getText()
                                + " is not compatible with type STRING. " + "Hence dropping the message.");
                        return null;
                    }
                    break;
                case FLOAT:
                    if (JsonToken.VALUE_NUMBER_FLOAT.equals(jsonToken)
                            || JsonToken.VALUE_NUMBER_INT.equals(jsonToken)) {
                        data[position] = attributeConverter.getPropertyValue(parser.getValueAsString(),
                                Attribute.Type.FLOAT);
                    } else {
                        log.error("Json message " + eventObject.toString()
                                + " contains incompatible attribute types and values. Value " + parser.getText()
                                + " is not compatible with type FLOAT. " + "Hence dropping the message.");
                        return null;
                    }
                    break;
                case LONG:
                    if (JsonToken.VALUE_NUMBER_INT.equals(jsonToken)) {
                        data[position] = parser.getValueAsLong();
                    } else {
                        log.error("Json message " + eventObject.toString()
                                + " contains incompatible attribute types and values. Value " + parser.getText()
                                + " is not compatible with type LONG. " + "Hence dropping the message.");
                        return null;
                    }
                    break;
                default:
                    return null;
                }
            }
        }
    }

    if (failOnMissingAttribute && (numberOfProvidedAttributes != attributesSize)) {
        log.error("Json message " + eventObject.toString()
                + " contains missing attributes. Hence dropping the message.");
        return null;
    }
    return event;
}

From source file:org.h2gis.drivers.geojson.GeoJsonReaderDriver.java

/**
 * Parses the metadata properties./*w w w  . j  a  v  a2s  . co  m*/
 *
 * @param jp
 * @return index
 */
private int parseMetadataProperties(JsonParser jp, StringBuilder metadataBuilder, int fieldIndex)
        throws IOException {
    jp.nextToken();//START_OBJECT {
    while (jp.nextToken() != JsonToken.END_OBJECT) {
        String fieldName = jp.getText().toUpperCase(); //FIELD_NAME columnName            
        JsonToken value = jp.nextToken();
        if (value == JsonToken.VALUE_STRING) {
            metadataBuilder.append(fieldName).append(" VARCHAR");
            fieldIndex++;
        } else if (value == JsonToken.VALUE_TRUE) {
            metadataBuilder.append(fieldName).append(" BOOLEAN");
            fieldIndex++;
        } else if (value == JsonToken.VALUE_FALSE) {
            metadataBuilder.append(fieldName).append(" BOOLEAN");
            fieldIndex++;
        } else if (value == JsonToken.VALUE_NUMBER_FLOAT) {
            metadataBuilder.append(fieldName).append(" DOUBLE");
            fieldIndex++;
        } else if (value == JsonToken.VALUE_NUMBER_INT) {
            metadataBuilder.append(fieldName).append(" INT");
            fieldIndex++;
        } else if (value == JsonToken.VALUE_NULL) {
            metadataBuilder.append(fieldName).append(" VARCHAR");
            fieldIndex++;
        } else {
            // TODO: ignore value.
        }
        metadataBuilder.append(",");
    }
    return fieldIndex;
}

From source file:de.undercouch.bson4jackson.BsonParserTest.java

/**
 * Checks if the parser returns a textual representation of arbitrary
 * tokens. See issue #23./*from   w  w  w.j a v a 2 s. c om*/
 * @throws Exception if something went wrong
 */
@Test
public void parseAsText() throws Exception {
    BSONObject o = new BasicBSONObject();
    o.put("Float", 5.0f);
    o.put("Int32", 1234);
    BSONEncoder enc = new BasicBSONEncoder();
    byte[] b = enc.encode(o);

    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    BsonFactory fac = new BsonFactory();
    BsonParser dec = fac.createParser(bais);

    assertEquals(JsonToken.START_OBJECT, dec.nextToken());

    assertEquals(JsonToken.FIELD_NAME, dec.nextToken());
    assertEquals("Float", dec.getCurrentName());
    assertEquals(JsonToken.VALUE_NUMBER_FLOAT, dec.nextToken());
    assertEquals(5.0f, dec.getFloatValue(), 0.00001);
    assertEquals("5.0", dec.getText());

    assertEquals(JsonToken.FIELD_NAME, dec.nextToken());
    assertEquals("Int32", dec.getCurrentName());
    assertEquals(JsonToken.VALUE_NUMBER_INT, dec.nextToken());
    assertEquals(1234, dec.getIntValue());
    assertEquals("1234", dec.getText());

    assertEquals(JsonToken.END_OBJECT, dec.nextToken());
}

From source file:org.apache.lucene.server.handlers.AddDocumentHandler.java

/** Parses the current json token into the corresponding
 *  java object. *//*from w w w  .  j  av  a 2 s .c o  m*/
private static Object getNativeValue(FieldDef fd, JsonToken token, JsonParser p) throws IOException {
    Object o;
    if (token == JsonToken.VALUE_STRING) {
        o = p.getText();
    } else if (token == JsonToken.VALUE_NUMBER_INT) {
        o = Long.valueOf(p.getLongValue());
    } else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
        o = Double.valueOf(p.getDoubleValue());
    } else if (token == JsonToken.VALUE_TRUE) {
        o = Boolean.TRUE;
    } else if (token == JsonToken.VALUE_FALSE) {
        o = Boolean.FALSE;
    } else if (fd.faceted.equals("hierarchy") && token == JsonToken.START_ARRAY) {
        if (fd.multiValued == false) {
            List<String> values = new ArrayList<>();
            while (true) {
                token = p.nextToken();
                if (token == JsonToken.END_ARRAY) {
                    break;
                } else if (token != JsonToken.VALUE_STRING) {
                    if (token == JsonToken.START_ARRAY) {
                        fail(fd.name, "expected array of strings, but saw array inside array");
                    } else {
                        fail(fd.name, "expected array of strings, but saw " + token + " inside array");
                    }
                }
                values.add(p.getText());
            }
            o = values;
        } else {
            List<List<String>> values = new ArrayList<>();
            while (true) {
                token = p.nextToken();
                if (token == JsonToken.END_ARRAY) {
                    break;
                } else if (token == JsonToken.START_ARRAY) {
                    List<String> sub = new ArrayList<>();
                    values.add(sub);
                    while (true) {
                        token = p.nextToken();
                        if (token == JsonToken.VALUE_STRING) {
                            sub.add(p.getText());
                        } else if (token == JsonToken.END_ARRAY) {
                            break;
                        } else {
                            fail(fd.name, "expected array of strings or array of array of strings, but saw "
                                    + token + " inside inner array");
                        }
                    }
                } else if (token == JsonToken.VALUE_STRING) {
                    List<String> sub = new ArrayList<>();
                    values.add(sub);
                    sub.add(p.getText());
                } else if (token == JsonToken.START_ARRAY) {
                    fail(fd.name, "expected array of strings, but saw array inside array");
                } else {
                    fail(fd.name, "expected array of strings, but saw " + token + " inside array");
                }
            }
            o = values;
        }
    } else if (fd.valueType == FieldDef.FieldValueType.LAT_LON) {
        if (token != JsonToken.START_ARRAY) {
            fail(fd.name, "latlon field must be [lat, lon] value; got " + token);
        }
        double[] latLon = new double[2];
        token = p.nextToken();
        if (token != JsonToken.VALUE_NUMBER_FLOAT) {
            fail(fd.name, "latlon field must be [lat, lon] value; got " + token);
        }
        latLon[0] = p.getDoubleValue();
        token = p.nextToken();
        if (token != JsonToken.VALUE_NUMBER_FLOAT) {
            fail(fd.name, "latlon field must be [lat, lon] value; got " + token);
        }
        latLon[1] = p.getDoubleValue();
        token = p.nextToken();
        if (token != JsonToken.END_ARRAY) {
            fail(fd.name, "latlon field must be [lat, lon] value; got " + token);
        }
        o = latLon;
    } else {
        String message;
        if (token == JsonToken.VALUE_NULL) {
            message = "null field value not supported; just omit this field from the document instead";
        } else {
            message = "value in inner object field value should be string, int/long, float/double or boolean; got "
                    + token;
        }

        fail(fd.name, message);

        // Dead code but compiler disagrees:
        o = null;
    }
    return o;
}

From source file:com.microsoft.azure.storage.table.CEKReturn.java

private static EdmType evaluateEdmType(JsonToken token, String value) {
    EdmType edmType = null;//from w ww . j  a va 2 s  .  co m

    if (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE) {
        edmType = EdmType.BOOLEAN;
    } else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
        edmType = EdmType.DOUBLE;
    } else if (token == JsonToken.VALUE_NUMBER_INT) {
        edmType = EdmType.INT32;
    } else {
        edmType = EdmType.STRING;
    }

    return edmType;
}

From source file:org.h2gis.drivers.geojson.GeoJsonReaderDriver.java

/**
 * Parses the properties of a feature//from  w  w  w .ja  v a 2 s  .com
 *
 * Syntax:
 *
 * "properties": {"prop0": "value0"}
 *
 * @param jsParser
 */
private void parseProperties(JsonParser jp, int fieldIndex) throws IOException, SQLException {
    jp.nextToken();//START_OBJECT {
    while (jp.nextToken() != JsonToken.END_OBJECT) {
        JsonToken value = jp.nextToken();
        if (value == JsonToken.VALUE_STRING) {
            getPreparedStatement().setObject(fieldIndex, jp.getText());
            fieldIndex++;
        } else if (value == JsonToken.VALUE_TRUE) {
            getPreparedStatement().setObject(fieldIndex, jp.getValueAsBoolean());
            fieldIndex++;
        } else if (value == JsonToken.VALUE_FALSE) {
            getPreparedStatement().setObject(fieldIndex, jp.getValueAsBoolean());
            fieldIndex++;
        } else if (value == JsonToken.VALUE_NUMBER_FLOAT) {
            getPreparedStatement().setObject(fieldIndex, jp.getValueAsDouble());
            fieldIndex++;
        } else if (value == JsonToken.VALUE_NUMBER_INT) {
            getPreparedStatement().setObject(fieldIndex, jp.getValueAsInt());
            fieldIndex++;
        } else if (value == JsonToken.VALUE_NULL) {
            getPreparedStatement().setObject(fieldIndex, null);
            fieldIndex++;
        } else {
            //ignore other value
        }
    }

}

From source file:pl.selvin.android.syncframework.content.BaseContentProvider.java

protected boolean Sync(String service, String scope, String params) {
    final Date start = new Date();
    boolean hasError = false;
    if (params == null)
        params = "";
    final SQLiteDatabase db = mDB.getWritableDatabase();
    final ArrayList<TableInfo> notifyTableInfo = new ArrayList<TableInfo>();

    final String download = String.format(contentHelper.DOWNLOAD_SERVICE_URI, service, scope, params);
    final String upload = String.format(contentHelper.UPLOAD_SERVICE_URI, service, scope, params);
    final String scopeServerBlob = String.format("%s.%s.%s", service, scope, _.serverBlob);
    String serverBlob = null;//from w  w  w .j a va 2  s .  co m
    Cursor cur = db.query(BlobsTable.NAME, new String[] { BlobsTable.C_VALUE }, BlobsTable.C_NAME + "=?",
            new String[] { scopeServerBlob }, null, null, null);
    final String originalBlob;
    if (cur.moveToFirst()) {
        originalBlob = serverBlob = cur.getString(0);
    } else {
        originalBlob = null;
    }
    cur.close();
    db.beginTransaction();
    try {
        boolean nochanges = false;
        if (serverBlob != null) {
            nochanges = !contentHelper.hasDirtTable(db, scope);
        }
        boolean resolve = false;
        final Metadata meta = new Metadata();
        final HashMap<String, Object> vals = new HashMap<String, Object>();
        final ContentValues cv = new ContentValues(2);
        JsonFactory jsonFactory = new JsonFactory();
        JsonToken current = null;
        String name = null;
        boolean moreChanges = false;
        boolean forceMoreChanges = false;
        do {
            final int requestMethod;
            final String serviceRequestUrl;
            final ContentProducer contentProducer;

            if (serverBlob != null) {
                requestMethod = HTTP_POST;
                if (nochanges) {
                    serviceRequestUrl = download;
                } else {
                    serviceRequestUrl = upload;
                    forceMoreChanges = true;
                }
                contentProducer = new SyncContentProducer(jsonFactory, db, scope, serverBlob, !nochanges,
                        notifyTableInfo, contentHelper);
                nochanges = true;
            } else {
                requestMethod = HTTP_GET;
                serviceRequestUrl = download;
                contentProducer = null;

            }
            if (moreChanges) {
                db.beginTransaction();
            }

            Result result = executeRequest(requestMethod, serviceRequestUrl, contentProducer);
            if (result.getStatus() == HttpStatus.SC_OK) {
                final JsonParser jp = jsonFactory.createParser(result.getInputStream());

                jp.nextToken(); // skip ("START_OBJECT(d) expected");
                jp.nextToken(); // skip ("FIELD_NAME(d) expected");
                if (jp.nextToken() != JsonToken.START_OBJECT)
                    throw new Exception("START_OBJECT(d - object) expected");
                while (jp.nextToken() != JsonToken.END_OBJECT) {
                    name = jp.getCurrentName();
                    if (_.__sync.equals(name)) {
                        current = jp.nextToken();
                        while (jp.nextToken() != JsonToken.END_OBJECT) {
                            name = jp.getCurrentName();
                            current = jp.nextToken();
                            if (_.serverBlob.equals(name)) {
                                serverBlob = jp.getText();
                            } else if (_.moreChangesAvailable.equals(name)) {
                                moreChanges = jp.getBooleanValue() || forceMoreChanges;
                                forceMoreChanges = false;
                            } else if (_.resolveConflicts.equals(name)) {
                                resolve = jp.getBooleanValue();
                            }
                        }
                    } else if (_.results.equals(name)) {
                        if (jp.nextToken() != JsonToken.START_ARRAY)
                            throw new Exception("START_ARRAY(results) expected");
                        while (jp.nextToken() != JsonToken.END_ARRAY) {
                            meta.isDeleted = false;
                            meta.tempId = null;
                            vals.clear();
                            while (jp.nextToken() != JsonToken.END_OBJECT) {
                                name = jp.getCurrentName();
                                current = jp.nextToken();
                                if (current == JsonToken.VALUE_STRING) {
                                    vals.put(name, jp.getText());
                                } else if (current == JsonToken.VALUE_NUMBER_INT) {
                                    vals.put(name, jp.getLongValue());
                                } else if (current == JsonToken.VALUE_NUMBER_FLOAT) {
                                    vals.put(name, jp.getDoubleValue());
                                } else if (current == JsonToken.VALUE_FALSE) {
                                    vals.put(name, 0L);
                                } else if (current == JsonToken.VALUE_TRUE) {
                                    vals.put(name, 1L);
                                } else if (current == JsonToken.VALUE_NULL) {
                                    vals.put(name, null);
                                } else {
                                    if (current == JsonToken.START_OBJECT) {
                                        if (_.__metadata.equals(name)) {
                                            while (jp.nextToken() != JsonToken.END_OBJECT) {
                                                name = jp.getCurrentName();
                                                jp.nextToken();
                                                if (_.uri.equals(name)) {
                                                    meta.uri = jp.getText();
                                                } else if (_.type.equals(name)) {
                                                    meta.type = jp.getText();
                                                } else if (_.isDeleted.equals(name)) {
                                                    meta.isDeleted = jp.getBooleanValue();
                                                } else if (_.tempId.equals(name)) {
                                                    meta.tempId = jp.getText();
                                                }
                                            }
                                        } else if (_.__syncConflict.equals(name)) {
                                            while (jp.nextToken() != JsonToken.END_OBJECT) {
                                                name = jp.getCurrentName();
                                                jp.nextToken();
                                                if (_.isResolved.equals(name)) {
                                                } else if (_.conflictResolution.equals(name)) {
                                                } else if (_.conflictingChange.equals(name)) {
                                                    while (jp.nextToken() != JsonToken.END_OBJECT) {
                                                        name = jp.getCurrentName();
                                                        current = jp.nextToken();
                                                        if (current == JsonToken.START_OBJECT) {
                                                            if (_.__metadata.equals(name)) {
                                                                while (jp.nextToken() != JsonToken.END_OBJECT) {

                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            // resolve conf

                                        } else if (_.__syncError.equals(name)) {
                                            while (jp.nextToken() != JsonToken.END_OBJECT) {
                                                name = jp.getCurrentName();
                                                jp.nextToken();
                                            }
                                        }
                                    }
                                }
                            }
                            TableInfo tab = contentHelper.getTableFromType(meta.type);
                            if (meta.isDeleted) {
                                tab.DeleteWithUri(meta.uri, db);
                            } else {
                                tab.SyncJSON(vals, meta, db);
                            }
                            if (!notifyTableInfo.contains(tab))
                                notifyTableInfo.add(tab);
                        }
                    }
                }
                jp.close();
                if (!hasError) {
                    cv.clear();
                    cv.put(BlobsTable.C_NAME, scopeServerBlob);
                    cv.put(BlobsTable.C_VALUE, serverBlob);
                    cv.put(BlobsTable.C_DATE, Calendar.getInstance().getTimeInMillis());
                    cv.put(BlobsTable.C_STATE, 0);
                    db.replace(BlobsTable.NAME, null, cv);
                    db.setTransactionSuccessful();
                    db.endTransaction();
                    if (DEBUG) {
                        Log.d(TAG, "CP-Sync: commit changes");
                    }
                    final ContentResolver cr = getContext().getContentResolver();
                    for (TableInfo t : notifyTableInfo) {
                        final Uri nu = contentHelper.getDirUri(t.name, false);
                        cr.notifyChange(nu, null, false);
                        // false - do not force sync cause we are in sync
                        if (DEBUG) {
                            Log.d(TAG, "CP-Sync: notifyChange table: " + t.name + ", uri: " + nu);
                        }

                        for (String n : t.notifyUris) {
                            cr.notifyChange(Uri.parse(n), null, false);
                            if (DEBUG) {
                                Log.d(TAG, "+uri: " + n);
                            }
                        }
                    }
                    notifyTableInfo.clear();
                }
            } else {
                if (DEBUG) {
                    Log.e(TAG, "Server error in fetching remote contacts: " + result.getStatus());
                }
                hasError = true;
                break;
            }
        } while (moreChanges);
    } catch (final ConnectTimeoutException e) {
        hasError = true;
        if (DEBUG) {
            Log.e(TAG, "ConnectTimeoutException", e);
        }
    } catch (final IOException e) {
        hasError = true;
        if (DEBUG) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } catch (final ParseException e) {
        hasError = true;
        if (DEBUG) {
            Log.e(TAG, "ParseException", e);
        }
    } catch (final Exception e) {
        hasError = true;
        if (DEBUG) {
            Log.e(TAG, "ParseException", e);
        }
    }
    if (hasError) {
        db.endTransaction();
        ContentValues cv = new ContentValues();
        cv.put(BlobsTable.C_NAME, scopeServerBlob);
        cv.put(BlobsTable.C_VALUE, originalBlob);
        cv.put(BlobsTable.C_DATE, Calendar.getInstance().getTimeInMillis());
        cv.put(BlobsTable.C_STATE, -1);
        db.replace(BlobsTable.NAME, null, cv);
    }
    /*-if (!hasError) {
    final ContentValues cv = new ContentValues(2);
     cv.put(BlobsTable.C_NAME, scopeServerBlob);
     cv.put(BlobsTable.C_VALUE, serverBlob);
     db.replace(BlobsTable.NAME, null, cv);
     db.setTransactionSuccessful();
    }
    db.endTransaction();
    if (!hasError) {
     for (String t : notifyTableInfo) {
    getContext().getContentResolver().notifyChange(getDirUri(t),
          null);
     }
    }*/
    if (DEBUG) {
        Helpers.LogInfo(start);
    }
    return !hasError;
}

From source file:org.apache.lucene.server.handlers.AddDocumentHandler.java

/** Parse one value for a field, which is either an
 *  object matching the type of the field, or a {boost:
 *  ..., value: ...}. *//*from   www .  j a v  a2s .  c o  m*/
private static boolean parseOneValue(FieldDef fd, JsonParser p, Document doc) throws IOException {

    Object o = null;
    float boost = 1.0f;

    JsonToken token = p.nextToken();
    if (token == JsonToken.START_ARRAY) {
        if ("hierarchy".equals(fd.faceted) || fd.valueType == FieldDef.FieldValueType.LAT_LON) {
            o = getNativeValue(fd, token, p);
        } else {
            if (fd.multiValued == false) {
                fail(fd.name, "expected single value, not array, since this field is not multiValued");
            }
            while (true) {
                if (!parseOneValue(fd, p, doc)) {
                    break;
                }
            }
            return true;
        }
    } else {

        if (token == JsonToken.END_ARRAY) {
            assert fd.multiValued;
            return false;
        }

        if (fd.fieldType.indexOptions() != IndexOptions.NONE && token == JsonToken.START_OBJECT) {
            // Parse a {boost: X, value: Y}
            while (true) {
                token = p.nextToken();
                if (token == JsonToken.END_OBJECT) {
                    break;
                }
                assert token == JsonToken.FIELD_NAME;
                String key = p.getText();
                if (key.equals("boost")) {
                    token = p.nextToken();
                    if (token == JsonToken.VALUE_NUMBER_INT || token == JsonToken.VALUE_NUMBER_FLOAT) {
                        boost = p.getFloatValue();
                    } else {
                        fail(fd.name, "boost in inner object field value must have float or int value; got: "
                                + token);
                    }
                } else if (key.equals("value")) {
                    o = getNativeValue(fd, p.nextToken(), p);
                } else {
                    fail(fd.name, "unrecognized json key \"" + key
                            + "\" in inner object field value; must be boost or value");
                }
            }
            if (o == null) {
                fail(fd.name, "missing 'value' key");
            }
        } else {
            // Parse a native value:
            o = getNativeValue(fd, token, p);
        }
    }

    parseOneNativeValue(fd, doc, o, boost);
    return true;
}

From source file:com.microsoft.windowsazure.storage.table.TableParser.java

private static EdmType evaluateEdmType(JsonToken token, String value) throws JsonParseException, IOException {
    EdmType edmType = null;// w  w  w .j  a v a  2  s  .  c om

    if (token == JsonToken.VALUE_NULL) {
        edmType = EdmType.NULL;
    } else if (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE) {
        edmType = EdmType.BOOLEAN;
    } else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
        edmType = EdmType.DOUBLE;
    } else if (token == JsonToken.VALUE_NUMBER_INT) {
        edmType = EdmType.INT32;
    } else {
        edmType = EdmType.STRING;
    }

    return edmType;
}