Example usage for com.fasterxml.jackson.core JsonParser getIntValue

List of usage examples for com.fasterxml.jackson.core JsonParser getIntValue

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonParser getIntValue.

Prototype

public abstract int getIntValue() throws IOException, JsonParseException;

Source Link

Document

Numeric accessor that can be called when the current token is of type JsonToken#VALUE_NUMBER_INT and it can be expressed as a value of Java int primitive type.

Usage

From source file:com.boundary.zoocreeper.Restore.java

private static ACL readACL(JsonParser jp) throws IOException {
    expectCurrentToken(jp, JsonToken.START_OBJECT);
    String scheme = null;//from   www  .j  ava 2 s  . c  o  m
    String id = null;
    int perms = -1;
    final Set<String> seenFields = Sets.newHashSet();
    while (jp.nextToken() != JsonToken.END_OBJECT) {
        jp.nextValue();
        final String fieldName = jp.getCurrentName();
        seenFields.add(fieldName);
        if (Backup.FIELD_ACL_SCHEME.equals(fieldName)) {
            scheme = jp.getValueAsString();
        } else if (Backup.FIELD_ACL_ID.equals(fieldName)) {
            id = jp.getValueAsString();
        } else if (Backup.FIELD_ACL_PERMS.equals(fieldName)) {
            perms = jp.getIntValue();
        } else {
            throw new IOException("Unexpected field: " + fieldName);
        }
    }
    if (!seenFields.containsAll(REQUIRED_ACL_FIELDS)) {
        throw new IOException("Missing required ACL fields: " + REQUIRED_ACL_FIELDS);
    }
    final Id zkId;
    if (Ids.ANYONE_ID_UNSAFE.getScheme().equals(scheme) && Ids.ANYONE_ID_UNSAFE.getId().equals(id)) {
        zkId = Ids.ANYONE_ID_UNSAFE;
    } else {
        zkId = new Id(scheme, id);
    }
    return new ACL(perms, zkId);
}

From source file:org.apache.streams.jackson.StreamsPeriodDeserializer.java

public Period deserialize(JsonParser jpar, DeserializationContext context) throws IOException {
    return Period.millis(jpar.getIntValue());
}

From source file:org.zalando.problem.StatusTypeDeserializer.java

@Override
public StatusType deserialize(final JsonParser json, final DeserializationContext context) throws IOException {
    final int statusCode = json.getIntValue();
    @Nullable/* w w w. j  ava  2s .  c o m*/
    final StatusType status = index.get(statusCode);
    return status == null ? new UnknownStatus(statusCode) : status;
}

From source file:org.camunda.bpm.example.spin.dataformat.configuration.MoneyJsonDeserializer.java

@Override
public Money deserialize(JsonParser parser, DeserializationContext context)
        throws IOException, JsonProcessingException {
    int price = parser.getIntValue();
    return new Money(price);
}

From source file:br.com.criativasoft.opendevice.core.json.EnumCodeDeserialize.java

@Override
public T deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
    int code = jsonParser.getIntValue();
    return getByCode(code);
}

From source file:com.ntsync.shared.RequestGenerator.java

private static Restrictions parseRestr(JsonParser jp) throws IOException {
    int maxContacts = Integer.MAX_VALUE;
    int maxGroups = Integer.MAX_VALUE;
    boolean photoSyncSupported = false;
    Date validUntil = null;// w ww  . j a va 2 s . c o m

    while (jp.nextToken() != JsonToken.END_OBJECT) {
        String configName = jp.getCurrentName();
        if (jp.nextToken() == null) {
            break;
        }
        if (PARAM_IS_PHOTO_SYNC_ENABLED.equals(configName)) {
            photoSyncSupported = jp.getBooleanValue();
        } else if (PARAM_MAX_CONTACTS.equals(configName)) {
            maxContacts = jp.getIntValue();
        } else if (PARAM_MAX_GROUPS.equals(configName)) {
            maxGroups = jp.getIntValue();
        } else if (PARAM_VALID_UNTIL.equals(configName)) {
            validUntil = new Date(jp.getLongValue());
        }
    }
    return new Restrictions(maxContacts, maxGroups, photoSyncSupported, validUntil);
}

From source file:com.google.openrtb.json.Test4Reader.java

@Override
protected void read(BidResponse.Builder msg, JsonParser par) throws IOException {
    if ("test4arr".equals(getCurrentName(par))) {
        for (startArray(par); endArray(par); par.nextToken()) {
            msg.addExtension(TestExt.testResponse4, par.getIntValue());
        }/*from w ww.ja  v a2 s . co m*/
    }
}

From source file:com.cinnober.msgcodec.json.TypeScannerJsonParserTest.java

private void assertNextIntValue(int exp, JsonParser p) throws IOException {
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(exp, p.getIntValue());
}

From source file:com.basho.riak.client.raw.http.QuorumDeserializer.java

@Override
public Quorum deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    JsonToken token = jp.getCurrentToken();
    switch (token) {
    case VALUE_STRING: {
        return new Quorum(Quora.fromString(jp.getText()));
    }//from  w ww .j  ava2 s.  c  o m
    case VALUE_NUMBER_INT: {
        return new Quorum(jp.getIntValue());
    }
    case VALUE_NULL: {
        return null;
    }
    default:
        break;
    }
    throw ctxt.mappingException(Quorum.class);
}

From source file:com.cedarsoft.serialization.jackson.ListSerializer.java

@Nullable
protected Object deserializeElement(@Nonnull JsonParser deserializeFrom, int index) throws IOException {
    //noinspection EnumSwitchStatementWhichMissesCases
    switch (deserializeFrom.getCurrentToken()) {
    case VALUE_STRING:
        return deserializeFrom.getText();
    case VALUE_NUMBER_INT:
        return deserializeFrom.getIntValue();
    case VALUE_NUMBER_FLOAT:
        return deserializeFrom.getDoubleValue();
    case VALUE_TRUE:
        return true;
    case VALUE_FALSE:
        return false;
    case VALUE_NULL:
        return null;
    }/*from   ww w .  j  a v a2 s.c om*/

    return deserializeFrom.getText();
}