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.inversoft.json.ZonedDateTimeDeserializer.java

@Override
public ZonedDateTime deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    JsonToken t = jp.getCurrentToken();/*from   w  w  w .  j a  va 2s .  c om*/
    long value;
    if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) {
        value = jp.getLongValue();
    } else if (t == JsonToken.VALUE_STRING) {
        String str = jp.getText().trim();
        if (str.length() == 0) {
            return null;
        }

        try {
            value = Long.parseLong(str);
        } catch (NumberFormatException e) {
            throw ctxt.mappingException(handledType());
        }
    } else {
        throw ctxt.mappingException(handledType());
    }

    return ZonedDateTime.ofInstant(Instant.ofEpochMilli(value), ZoneOffset.UTC);
}

From source file:io.swagger.inflector.config.DirectionDeserializer.java

@Override
public Set<Configuration.Direction> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.VALUE_FALSE) {
        return EnumSet.noneOf(Configuration.Direction.class);
    } else if (token == JsonToken.VALUE_TRUE) {
        return EnumSet.allOf(Configuration.Direction.class);
    } else if (token == JsonToken.START_ARRAY) {
        final Set<Configuration.Direction> items = EnumSet.noneOf(Configuration.Direction.class);
        while (true) {
            final JsonToken next = jp.nextToken();
            if (next == JsonToken.VALUE_STRING) {
                final String name = jp.getText();
                items.add(Configuration.Direction.valueOf(name));
            } else if (next == JsonToken.END_ARRAY) {
                return items;
            } else {
                break;
            }/*from   w ww .  ja  v  a2  s  .  c  o m*/
        }
    }
    throw ctxt.mappingException(Configuration.Direction.class);
}

From source file:org.elasticsoftware.elasticactors.base.serialization.JacksonScheduledMessageRefDeserializer.java

@Override
public ScheduledMessageRef deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonToken curr = jp.getCurrentToken();
    // Usually should just get string value:
    if (curr == JsonToken.VALUE_STRING) {
        return scheduledMessageRefFactory.create(jp.getText());
    }//from   w  w w.  j  a  v  a2  s  .  c  om
    throw ctxt.mappingException(_valueClass, curr);
}

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

public CallResultMessage(JsonParser jp) throws IOException {
    super(WampMessageType.CALLRESULT);

    if (jp.nextToken() != JsonToken.VALUE_STRING) {
        throw new IOException();
    }/*from  www. j av  a2 s .c  o m*/
    this.callID = jp.getValueAsString();

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

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

public UnsubscribeMessage(JsonParser jp, WampSession wampSession) throws IOException {
    super(WampMessageType.UNSUBSCRIBE);
    if (jp.nextToken() != JsonToken.VALUE_STRING) {
        throw new IOException();
    }//from  w  w w  .  j  a v  a2  s.c om
    setTopicURI(replacePrefix(jp.getValueAsString(), wampSession));
}

From source file:org.hbz.oerworldmap.JsonDecoder.java

private void handleValue(final JsonToken currentToken, final String key)
        throws IOException, JsonParseException {
    {//from   ww w.  j ava  2s  .c o  m
        if (JsonToken.VALUE_STRING == currentToken || JsonToken.VALUE_NUMBER_INT == currentToken
                || JsonToken.VALUE_NUMBER_FLOAT == currentToken) {
            final String value = this.jsonParser.getText();
            JsonDecoder.LOG.debug("key=" + key + " value=" + value);
            getReceiver().literal(key, value);
        }
    }
}

From source file:de.taimos.dvalin.interconnect.model.DateTimeDeserializerWithTZ.java

@Override
public DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonToken t = jp.getCurrentToken();/*from  w  w w  .ja va 2s.c om*/
    if (t == JsonToken.VALUE_NUMBER_INT) {
        return new DateTime(jp.getLongValue(), DateTimeZone.forTimeZone(ctxt.getTimeZone()));
    }
    if (t == JsonToken.VALUE_STRING) {
        String str = jp.getText().trim();
        if (str.length() == 0) { // [JACKSON-360]
            return null;
        }
        // catch serialized time zones
        if ((str.charAt(str.length() - 6) == '+') || (str.charAt(str.length() - 1) == 'Z')
                || (str.charAt(str.length() - 6) == '-')) {
            return new DateTime(str);
        }
        return new DateTime(str, DateTimeZone.forTimeZone(ctxt.getTimeZone()));
    }
    ctxt.handleUnexpectedToken(this.handledType(), jp);
    // never reached
    return null;
}

From source file:javaslang.jackson.datatype.deserialize.CharSeqDeserializer.java

@Override
public CharSeq deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    Object obj = deserializer.deserialize(p, ctxt);
    if (obj instanceof String) {
        return CharSeq.of((String) obj);
    } else {//from  w  ww.  j  a v a 2  s .  c o  m
        throw ctxt.wrongTokenException(p, JsonToken.VALUE_STRING,
                "CharSeq can only be deserialized from String");
    }
}

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

public WelcomeMessage(JsonParser jp) throws IOException {
    super(WampMessageType.WELCOME);

    if (jp.nextToken() != JsonToken.VALUE_STRING) {
        throw new IOException();
    }/*from  w w  w  . jav  a  2  s  .co m*/
    this.sessionId = jp.getValueAsString();

    if (jp.nextToken() != JsonToken.VALUE_NUMBER_INT) {
        throw new IOException();
    }
    this.protocolVersion = jp.getValueAsInt();

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

}

From source file:com.redhat.red.build.koji.model.json.util.MavenGAVDeserializer.java

@Override
public SimpleProjectVersionRef deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    String g = null;/*  w ww.  j  a va 2s  .com*/
    String a = null;
    String v = null;

    JsonToken token = null;
    while ((token = jp.nextToken()) != JsonToken.END_OBJECT) {
        if (token == JsonToken.VALUE_STRING) {
            String field = jp.getCurrentName();
            switch (field) {
            case ("group_id"): {
                g = jp.getText();
                break;
            }
            case ("artifact_id"): {
                a = jp.getText();
                break;
            }
            case ("version"): {
                v = jp.getText();
                break;
            }
            default: {
                Logger logger = LoggerFactory.getLogger(getClass());
                logger.debug("Ignoring unknown field: {}", field);
            }
            }
        }
    }

    if (isEmpty(g) || isEmpty(a) || isEmpty(v)) {
        throw new KojiJsonException("Invalid GAV: " + g + ":" + a + ":" + v);
    }

    return new SimpleProjectVersionRef(g, a, v);
}