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

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

Introduction

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

Prototype

JsonToken VALUE_STRING

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

Click Source Link

Document

VALUE_STRING is returned when a String token is encountered in value context (array element, field value, or root-level stand-alone value)

Usage

From source file:com.basistech.rosette.dm.jackson.array.ListAttributeArrayDeserializer.java

@Override
@SuppressWarnings("unchecked")
public ListAttribute deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    if (jp.getCurrentToken() == JsonToken.START_ARRAY) { // this is what we expect.
        // we advance to be in the same place the 'else' will be -- the first FIELD_NAME.
        jp.nextToken();//from  w ww.  j av a 2 s  .  c o m
    } else {
        throw ctxt.wrongTokenException(jp, JsonToken.START_ARRAY,
                "ListAttributeDeserializer called not array start.");
    }

    if (jp.getCurrentToken() != JsonToken.VALUE_STRING) {
        throw ctxt.mappingException("Expected VALUE_STRING for item type.");
    }
    String itemTypeKeyName = jp.getText();

    KnownAttribute attribute = KnownAttribute.getAttributeForKey(itemTypeKeyName);
    if (attribute == null) {
        attribute = KnownAttribute.UNKNOWN;
    }
    Class<? extends BaseAttribute> itemClass = attribute.attributeClass();

    ListAttribute.Builder<BaseAttribute> builder = new ListAttribute.Builder<>(attribute.attributeClass());
    List<BaseAttribute> items = Lists.newArrayList();

    if (jp.nextToken() != JsonToken.START_ARRAY) {
        throw ctxt.wrongTokenException(jp, JsonToken.START_ARRAY, "No array of values for list.");
    }

    // we just read the elements as we see them,
    while (jp.nextToken() != JsonToken.END_ARRAY) {
        // the START_ARRAY case, which is _normal_. Read the elements.
        items.add(jp.readValueAs(itemClass));
    }
    builder.setItems(items);
    // we are still in the top-level array ...
    if (jp.nextToken() != JsonToken.START_OBJECT) {
        throw ctxt.wrongTokenException(jp, JsonToken.START_OBJECT, "No extended properties for list.");
    }
    Map<String, Object> props = jp.readValueAs(new TypeReference<Map<String, Object>>() {
    });
    for (Map.Entry<String, Object> me : props.entrySet()) {
        builder.extendedProperty(me.getKey(), me.getValue());
    }
    jp.nextToken(); // consume the END_OBJECT of the extended props
    return builder.build();
}

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

public CallMessage(JsonParser jp, WampSession wampSession) throws IOException {
    super(WampMessageType.CALL);

    if (jp.nextToken() != JsonToken.VALUE_STRING) {
        throw new IOException();
    }//  w ww. j ava  2  s  .c om
    this.callID = jp.getValueAsString();

    if (jp.nextToken() != JsonToken.VALUE_STRING) {
        throw new IOException();
    }
    this.procURI = replacePrefix(jp.getValueAsString(), wampSession);

    List<Object> args = new ArrayList<>();
    while (jp.nextToken() != JsonToken.END_ARRAY) {
        args.add(jp.readValueAs(Object.class));
    }

    if (!args.isEmpty()) {
        this.arguments = Collections.unmodifiableList(args);
    } else {
        this.arguments = null;
    }
}

From source file:com.wavemaker.commons.json.deserializer.WMDateDeSerializer.java

@Override
public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
    JsonToken currentToken = jsonParser.getCurrentToken();
    if (currentToken == JsonToken.VALUE_STRING) {
        String value = jsonParser.getText();
        return getDate(value);
    }//from  www  .  j  a  va  2s .c o m
    return super.deserialize(jsonParser, deserializationContext);
}

From source file:com.turn.shapeshifter.transformers.DateTimeTransformer.java

/** 
 * @param node a date formatted using ISO 8601
 *//*from  ww  w. j av  a2  s  . c  o m*/
@Override
public Object parse(JsonNode node) {
    Preconditions.checkArgument(JsonToken.VALUE_STRING.equals(node.asToken()));
    String nodeValue = node.asText();
    return new Long(ISO_8601.parseMillis(nodeValue));
}

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  v a2  s . com*/
    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:org.lobid.lodmill.JsonDecoder.java

private void handleValue(final JsonToken currentToken, final String key)
        throws IOException, JsonParseException {
    {/*from   w  w  w  .j a v  a2s  .  co m*/
        if (JsonToken.VALUE_STRING == currentToken || JsonToken.VALUE_NUMBER_INT == currentToken
                || JsonToken.VALUE_NUMBER_FLOAT == currentToken) {
            final String value = this.jsonParser.getText();
            LOG.debug("key=" + key + " value=" + value);
            getReceiver().literal(key, value);
        }
    }
}

From source file:dk.dma.navnet.messages.TextMessageReader.java

public String takeString() throws IOException {
    if (jp.nextToken() != JsonToken.VALUE_STRING) {
        throw new IOException("Expected an String, but was '" + jp.getText() + "'");
    }//ww w  . j  av  a2s .c  om
    return jp.getText();
}

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

public PublishMessage(JsonParser jp, WampSession wampSession) throws IOException {
    super(WampMessageType.PUBLISH);

    if (jp.nextToken() != JsonToken.VALUE_STRING) {
        throw new IOException();
    }/*from  ww  w  .  j  av  a2 s.  c  o m*/
    setTopicURI(replacePrefix(jp.getValueAsString(), wampSession));

    jp.nextToken();
    this.event = jp.readValueAs(Object.class);

    if (jp.nextToken() != JsonToken.END_ARRAY) {
        if (jp.getCurrentToken() == JsonToken.VALUE_TRUE || jp.getCurrentToken() == JsonToken.VALUE_FALSE) {
            this.excludeMe = jp.getValueAsBoolean();

            this.exclude = null;

            this.eligible = null;

            if (jp.nextToken() != JsonToken.END_ARRAY) {
                // Wrong message format, excludeMe should not be followed by
                // any value
                throw new IOException();
            }
        } else {
            this.excludeMe = null;

            TypeReference<Set<String>> typRef = new TypeReference<Set<String>>() {
                // nothing here
            };

            if (jp.getCurrentToken() != JsonToken.START_ARRAY) {
                throw new IOException();
            }
            this.exclude = jp.readValueAs(typRef);

            if (jp.nextToken() == JsonToken.START_ARRAY) {
                this.eligible = jp.readValueAs(typRef);
            } else {
                this.eligible = null;
            }
        }
    } else {
        this.excludeMe = null;
        this.exclude = null;
        this.eligible = null;
    }

}

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

public EventMessage(JsonParser jp, WampSession wampSession) throws IOException {
    super(WampMessageType.EVENT);

    if (jp.nextToken() != JsonToken.VALUE_STRING) {
        throw new IOException();
    }/*from w w w  .  j av a  2 s . c om*/
    setTopicURI(replacePrefix(jp.getValueAsString(), wampSession));

    jp.nextToken();
    this.event = jp.readValueAs(Object.class);
}

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 w  ww.ja va 2  s  . c o  m*/

        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;
}