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:com.allogy.json.jackson.joda.ISOLocalDateDeserializer.java

@Override
public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
    String text = jsonParser.getText();
    try {/*from www .  ja va  2  s  .  c  o  m*/
        return localDateFormatter.parseLocalDate(text);
    } catch (Throwable throwable) {
        throw new InvalidFormatException(throwable.getMessage(), text, String.class);
    }
}

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

@Override
public Class<?> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    try {// ww  w  .  j a va 2s.  com
        return Class.forName(jp.getText());
    } catch (ClassNotFoundException e) {
        logger.error("Could not deserialize json representation of URI " + jp.getText()
                + " into URI object because " + e.getMessage(), e);
    }
    return null;
}

From source file:com.allogy.json.jackson.joda.ISOPeriodDeserializer.java

@Override
public Period deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
    String textValue = jsonParser.getText();
    try {//  w w w .j a va2  s . co  m
        return new Period(textValue);
    } catch (Throwable throwable) {
        throw new InvalidFormatException(throwable.getMessage(), textValue, String.class);
    }
}

From source file:com.illumina.basespace.util.BigDecimalDeserializer.java

@Override
public BigDecimal deserialize(JsonParser parser, DeserializationContext context)
        throws IOException, JsonProcessingException {
    try {//from ww w .  ja v  a 2 s .  c o m
        return new BigDecimal(parser.getText());
    } catch (Throwable t) {
        logger.log(Level.SEVERE, "Error deserializing bigdecimal from JSON object", t);
        return null;
    }
}

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

@Override
public Mnemonic deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    try {/*from w w w.  j  a  v a2  s . co m*/
        return Mnemonic.of(jp.getText());
    } catch (IllegalArgumentException e) {
        String msg = "Could not deserialize json representation of Mnemonic " + jp.getText()
                + " into a Mnemonic object because " + e.getMessage();
        logger.error(msg, e);
        throw new JsonParseException(msg, jp.getCurrentLocation());
    }
}

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

@Override
public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    return ISODateTimeFormat.dateTimeParser().parseLocalDate(jp.getText());
}

From source file:com.strategicgains.restexpress.serialization.json.JacksonTimepointDeserializer.java

@Override
public Date deserialize(JsonParser parser, DeserializationContext context)
        throws IOException, JsonProcessingException {
    try {//  w w  w.  j av a 2 s .c o  m
        return adapter.parse(parser.getText());
    } catch (ParseException e) {
        throw new DeserializationException(e);
    }
}

From source file:com.wealdtech.jackson.modules.TriValDeserializer.java

@Override
public TriVal<?> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    if (jp.getCurrentToken() == JsonToken.VALUE_STRING && jp.getText().length() == 0) {
        return TriVal.clear();
    }/*from   w w w . ja  v a 2s  . c  o  m*/
    Object reference = ctxt.findRootValueDeserializer(_referenceType).deserialize(jp, ctxt);
    return TriVal.of(reference);
}

From source file:org.agorava.yammer.impl.YammerDateDeserializer.java

@Override
public Date deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    try {/*from w ww.j  a  v  a  2  s.c o m*/
        return createDateFormatter().parse(jp.getText());
    } catch (ParseException e) {
        return null;
    }
}

From source file:com.animedetour.api.sched.deserialization.PanelDateDeserializerTest.java

@Test
public void deserialization() throws IOException {
    PanelDateDeserializer deserializer = new PanelDateDeserializer();
    JsonParser parser = Mockito.mock(JsonParser.class);
    Mockito.when(parser.getCurrentToken()).thenReturn(JsonToken.VALUE_STRING);
    Mockito.when(parser.getText()).thenReturn("1991-09-04 13:06:02");

    ReadableInstant deserialized = deserializer.deserialize(parser, null);
    DateTime dateTime = new DateTime(deserialized);

    assertEquals(1991, dateTime.getYear());
    assertEquals(9, dateTime.getMonthOfYear());
    assertEquals(4, dateTime.getDayOfMonth());
    assertEquals(13, dateTime.getHourOfDay());
    assertEquals(6, dateTime.getMinuteOfHour());
    assertEquals(2, dateTime.getSecondOfMinute());
}