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

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

Introduction

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

Prototype

public abstract String getText() throws IOException, JsonParseException;

Source Link

Document

Method for accessing textual representation of the current token; if no current token (before first call to #nextToken , or after encountering end-of-input), returns null.

Usage

From source file:ca.ualberta.physics.cssdp.util.JSONDateTimeDeserializer.java

@Override
public DateTime deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    try {// w ww  .ja  va2s  .c  o  m
        return ISODateTimeFormat.dateTimeParser().parseDateTime(jp.getText());
    } catch (Exception e) {
        e.printStackTrace();
        throw new JsonParseException(e.getMessage(), jp.getCurrentLocation());
    }
}

From source file:com.netflix.genie.common.util.JsonDateDeserializer.java

/**
 * {@inheritDoc}//from   w  ww .j av  a  2  s  . co  m
 */
@Override
public Date deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
    final DateFormat format = new ISO8601DateFormat();

    final String text = parser.getText();

    if (StringUtils.isBlank(text)) {
        return null;
    }

    try {
        return format.parse(text);
    } catch (final ParseException pe) {
        throw new IOException(pe);
    }
}

From source file:com.cedarsoft.serialization.serializers.jackson.VersionSerializer.java

@Override
public Version deserialize(@Nonnull JsonParser deserializeFrom, @Nonnull Version formatVersion)
        throws VersionException, IOException, JsonProcessingException {
    String version = deserializeFrom.getText();
    return Version.parse(version);
}

From source file:com.cedarsoft.serialization.jackson.test.EmailSerializer.java

@Nonnull
@Override/* w  w  w.j av a 2  s .  c  om*/
public Email deserialize(@Nonnull JsonParser deserializeFrom, @Nonnull Version formatVersion)
        throws IOException, VersionException, JsonProcessingException {
    return new Email(deserializeFrom.getText());
}

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

@Override
public StatementRank deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    StatementRank result;/*from   w  ww  .  j a va 2 s.c o  m*/
    String text = jp.getText();

    if (text != null) {
        text = text.trim();
    }

    switch (text) {
    case "0":
        result = StatementRank.DEPRECATED;
        break;
    case "1":
        result = StatementRank.NORMAL;
        break;
    case "2":
        result = StatementRank.PREFERRED;
        break;
    default:
        result = null;
    }

    return result;
}

From source file:ca.ualberta.physics.cssdp.util.JSONLocalDateTimeDeserializer.java

@Override
public LocalDateTime deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    try {/*from   w  ww  . j  a  v a  2s  .c  o  m*/
        return ISODateTimeFormat.dateTimeParser().parseLocalDateTime(jp.getText());
    } catch (Exception e) {
        e.printStackTrace();
        throw new JsonParseException(e.getMessage(), jp.getCurrentLocation());
    }
}

From source file:com.cedarsoft.serialization.serializers.jackson.BaseNameSerializer.java

@Nonnull
@Override/*from w ww . j  a  v  a  2  s . co m*/
public BaseName deserialize(@Nonnull JsonParser deserializeFrom, @Nonnull Version formatVersion)
        throws VersionException, IOException, JsonProcessingException {
    return new BaseName(deserializeFrom.getText());
}

From source file:webby.commons.io.jackson.OffsetDateTimeDeserializer.java

@Override
public OffsetDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    switch (parser.getCurrentToken()) {
    case VALUE_STRING:
        String string = parser.getText().trim();
        if (prepareFn != null)
            string = prepareFn.apply(string);
        if (string == null || string.length() == 0)
            return null;
        return OffsetDateTime.parse(string, formatter);
    }/*from   ww w .  ja v  a 2 s.c  om*/

    throw context.wrongTokenException(parser, JsonToken.START_ARRAY, "Expected array or string.");
}

From source file:org.springframework.social.weibo.api.impl.json.DateTimeDeserializer.java

@Override
public DateTime deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    return DateTimeFormat.forPattern(getDateFormat()).withLocale(Locale.ENGLISH).parseDateTime(jp.getText());
}

From source file:org.springframework.social.betaseries.api.impl.json.BSDateAndTimeDeserializer.java

@Override
public Date deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    try {/*from  www.ja  v a 2  s  .com*/
        return new SimpleDateFormat(BS_DATE_FORMAT, Locale.ENGLISH).parse(jp.getText());
    } catch (ParseException e) {
        return null;
    }
}