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

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

Introduction

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

Prototype

JsonToken END_ARRAY

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

Click Source Link

Document

END_ARRAY is returned when encountering ']' which signals ending of an Array value

Usage

From source file:org.onosproject.north.aaa.api.parser.impl.RestAccessParser.java

@Override
public Set<RestAccess> parseJson(InputStream stream) throws IOException, ParseException {
    // begin parsing JSON to Application class
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(stream);
    JsonParser jp = jsonNode.traverse();
    Set<RestAccess> restAccessSet = new HashSet<>();

    // continue parsing the token till the end of input is reached
    while (!jp.isClosed()) {
        // get the token
        JsonToken token = jp.nextToken();
        // if its the last token then we are done
        if (token == null) {
            break;
        }/*from   ww  w  .  j  a va2s.co m*/

        if (JsonToken.FIELD_NAME.equals(token) && "accesses".equals(jp.getCurrentName())) {
            token = jp.nextToken();
            if (!JsonToken.START_ARRAY.equals(token)) {
                // bail out
                throw new ParseException("expected ARRAY after accesses");
            }

            while (true) {
                token = jp.nextToken();
                if (JsonToken.END_ARRAY.equals(token)) {
                    // bail out
                    break;
                }

                if (JsonToken.START_OBJECT.equals(token)) {
                    RestAccess restAccess = jsonToRestAccess(jp);
                    restAccessSet.add(restAccess);
                }
            }
        }
    }
    return restAccessSet;
}

From source file:de.upb.wdqa.wdvd.datamodel.oldjson.jackson.deserializers.OldLabelsDescriptionsDeserializer.java

@Override
public LinkedHashMap<String, String> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    LinkedHashMap<String, String> result = null;

    // Is the alias broken, i.e., it starts with '['
    if (jp.getCurrentToken().equals(JsonToken.START_ARRAY)) {
        result = new LinkedHashMap<String, String>();
        jp.nextToken();/*from w  w  w  .  j  a  va  2s  .  c om*/
        if (!jp.getCurrentToken().equals(JsonToken.END_ARRAY)) {
            logger.warn("Token " + JsonToken.END_ARRAY + " expected");
        }
    } else {
        ObjectCodec mapper = jp.getCodec();
        result = mapper.readValue(jp, new TypeReference<LinkedHashMap<String, String>>() {
        });
    }

    return result;
}

From source file:de.upb.wdqa.wdvd.datamodel.oldjson.jackson.deserializers.OldSitelinksDeserializer.java

@Override
public LinkedHashMap<String, OldJacksonSiteLink> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    LinkedHashMap<String, OldJacksonSiteLink> result = null;

    // Is the alias broken, i.e., it starts with '['
    if (jp.getCurrentToken().equals(JsonToken.START_ARRAY)) {
        result = new LinkedHashMap<String, OldJacksonSiteLink>();
        jp.nextToken();//from  w w w. j a v  a  2  s  .  com
        if (!jp.getCurrentToken().equals(JsonToken.END_ARRAY)) {
            logger.warn("Token " + JsonToken.END_ARRAY + " expected");
        }
    } else {
        ObjectCodec mapper = jp.getCodec();
        result = mapper.readValue(jp, new TypeReference<LinkedHashMap<String, OldJacksonSiteLink>>() {
        });
    }

    return result;
}

From source file:org.apache.batchee.jackson.JacksonJsonReader.java

@Override
protected Object doRead() throws Exception {
    JsonToken token;//from ww  w .ja v  a  2 s  .  c o  m
    do {
        token = parser.nextToken();
    } while ((token != JsonToken.START_OBJECT && token != end)
            || (end == null && (token == JsonToken.END_ARRAY || token == JsonToken.END_OBJECT)));

    if (clazz == null) {
        parser.readValueAsTree();
    }
    return parser.readValueAs(clazz);
}

From source file:org.ojai.beans.jackson.DocumentParser.java

@Override
public JsonToken nextToken() throws IOException, JsonParseException {
    if (tokens.isEmpty() && (_currEventType = r.next()) != null) {
        if (r.inMap() && r.getFieldName() != null && _currEventType != EventType.END_MAP
                && _currEventType != EventType.END_ARRAY) {
            tokens.add(JsonToken.FIELD_NAME);
        }/*from www.  j a v a  2 s .  com*/

        switch (_currEventType) {
        case START_ARRAY:
            tokens.add(JsonToken.START_ARRAY);
            break;
        case END_ARRAY:
            tokens.add(JsonToken.END_ARRAY);
            break;
        case START_MAP:
            tokens.add(JsonToken.START_OBJECT);
            break;
        case END_MAP:
            tokens.add(JsonToken.END_OBJECT);
            break;
        case NULL:
            tokens.add(JsonToken.VALUE_NULL);
            break;
        case STRING:
            tokens.add(JsonToken.VALUE_STRING);
            break;
        case BYTE:
        case SHORT:
        case INT:
        case LONG:
            tokens.add(JsonToken.VALUE_NUMBER_INT);
            break;
        case DECIMAL:
        case DOUBLE:
        case FLOAT:
            tokens.add(JsonToken.VALUE_NUMBER_FLOAT);
            break;
        case BOOLEAN:
            tokens.add(r.getBoolean() ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE);
            break;
        case DATE:
        case TIME:
        case TIMESTAMP:
        case INTERVAL:
        case BINARY:
            tokens.add(JsonToken.VALUE_EMBEDDED_OBJECT);
            break;
        }
    }
    _currToken = tokens.isEmpty() ? JsonToken.NOT_AVAILABLE : tokens.remove();
    return _currToken;
}

From source file:org.onosproject.north.aaa.api.parser.impl.ClientParser.java

@Override
public Set<ClientCredential> parseJson(InputStream stream) throws IOException, ParseException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(stream);
    JsonParser jp = jsonNode.traverse();
    Set<ClientCredential> clientSet = new HashSet<>();

    // continue parsing the token till the end of input is reached
    while (!jp.isClosed()) {
        // get the token
        JsonToken token = jp.nextToken();
        // if its the last token then we are done
        if (token == null) {
            break;
        }/*  w ww.  ja  va 2 s.  c om*/

        if (JsonToken.FIELD_NAME.equals(token) && "clients".equals(jp.getCurrentName())) {
            token = jp.nextToken();
            if (!JsonToken.START_ARRAY.equals(token)) {
                // bail out
                throw new ParseException("expected ARRAY after clients");
            }

            while (true) {
                token = jp.nextToken();
                if (JsonToken.END_ARRAY.equals(token)) {
                    // bail out
                    break;
                }

                if (JsonToken.START_OBJECT.equals(token)) {
                    ClientCredential client = jsonToClientCredential(jp);
                    clientSet.add(client);
                }
            }
        }
    }
    return clientSet;
}

From source file:org.onosproject.north.aaa.api.parser.impl.UserParser.java

@Override
public Set<User> parseJson(InputStream stream) throws IOException, ParseException {
    // begin parsing JSON to Application class
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(stream);
    JsonParser jp = jsonNode.traverse();
    Set<User> userSet = new HashSet<>();

    // continue parsing the token till the end of input is reached
    while (!jp.isClosed()) {
        // get the token
        JsonToken token = jp.nextToken();
        // if its the last token then we are done
        if (token == null) {
            break;
        }//from  w w w . j av  a 2  s.  c o  m
        if (JsonToken.FIELD_NAME.equals(token) && "users".equals(jp.getCurrentName())) {
            token = jp.nextToken();
            if (!JsonToken.START_ARRAY.equals(token)) {
                // bail out
                throw new ParseException("expected ARRAY after users");
            }

            while (true) {
                token = jp.nextToken();
                if (JsonToken.END_ARRAY.equals(token)) {
                    // bail out
                    break;
                }
                if (JsonToken.START_OBJECT.equals(token)) {
                    User user = jsonToUser(jp);
                    userSet.add(user);
                }
            }
        }
    }
    return userSet;
}

From source file:de.upb.wdqa.wdvd.datamodel.oldjson.jackson.deserializers.OldAliasesDeserializer.java

@Override
public LinkedHashMap<String, List<String>> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    LinkedHashMap<String, List<String>> result = new LinkedHashMap<String, List<String>>();

    // Is the alias broken, i.e., it starts with '['
    if (jp.getCurrentToken().equals(JsonToken.START_ARRAY)) {
        jp.nextToken();/*  w w w. j  a va  2 s .  com*/
        if (!jp.getCurrentToken().equals(JsonToken.END_ARRAY)) {
            logger.warn("Token " + JsonToken.END_ARRAY + " expected");
        }
    } else {
        ObjectCodec mapper = jp.getCodec();
        result = mapper.readValue(jp, new TypeReference<LinkedHashMap<String, OldAliasList>>() {
        });
    }

    return result;
}

From source file:ch.rasc.wampspring.message.CallErrorMessage.java

public CallErrorMessage(JsonParser jp) throws IOException {
    super(WampMessageType.CALLERROR);

    if (jp.nextToken() != JsonToken.VALUE_STRING) {
        throw new IOException();
    }//  w w  w .  j  a va  2 s . c  o  m
    this.callID = jp.getValueAsString();

    if (jp.nextToken() != JsonToken.VALUE_STRING) {
        throw new IOException();
    }
    this.errorURI = jp.getValueAsString();

    if (jp.nextToken() != JsonToken.VALUE_STRING) {
        throw new IOException();
    }
    this.errorDesc = jp.getValueAsString();

    if (jp.nextToken() != JsonToken.END_ARRAY) {
        this.errorDetails = jp.readValueAs(Object.class);
    } else {
        this.errorDetails = null;
    }
}

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

@Nonnull
private static JsonToken findOutToken(@Nonnull JsonToken inToken) {
    switch (inToken) {
    case START_OBJECT:
        return JsonToken.END_OBJECT;
    case START_ARRAY:
        return JsonToken.END_ARRAY;
    }/*from  w  ww .  j a v a 2  s .  c o  m*/

    throw new SerializationException(SerializationException.Details.INVALID_STATE,
            "No end token found for <" + inToken + ">");
}