use of com.fasterxml.jackson.core.JsonToken in project atlasmap by atlasmap.
the class ActionsJsonDeserializer method processPrependJsonToken.
protected Prepend processPrependJsonToken(JsonParser jsonToken) throws IOException {
Prepend action = new Prepend();
if (JsonToken.END_ARRAY.equals(jsonToken.currentToken()) || JsonToken.END_OBJECT.equals(jsonToken.currentToken())) {
return action;
}
JsonToken nextToken = null;
do {
if (JsonToken.START_OBJECT.equals(jsonToken.currentToken())) {
jsonToken.nextToken();
}
switch(jsonToken.getCurrentName()) {
case ActionsJsonSerializer.STRING:
jsonToken.nextToken();
action.setString(jsonToken.getValueAsString());
break;
default:
break;
}
nextToken = jsonToken.nextToken();
} while (!JsonToken.END_ARRAY.equals(nextToken) && !JsonToken.END_OBJECT.equals(nextToken));
return action;
}
use of com.fasterxml.jackson.core.JsonToken in project Payara by payara.
the class ProgressStatusDTOJsonProprietaryReader method readFrom.
@Override
public ProgressStatusDTO readFrom(final InputStream is, final String contentType) throws IOException {
try (JsonParser jp = factory.createJsonParser(is)) {
// sorounding object
JsonToken token = jp.nextToken();
// Name progress-status
jp.nextToken();
JsonToken token2 = jp.nextToken();
if (token != JsonToken.START_OBJECT || token2 != JsonToken.START_OBJECT || !"progress-status".equals(jp.getCurrentName())) {
throw new IOException("Not expected type (progress-status) but (" + jp.getCurrentName() + ")");
}
return readProgressStatus(jp);
}
}
use of com.fasterxml.jackson.core.JsonToken in project Payara by payara.
the class ProgressStatusEventJsonProprietaryReader method readFrom.
@Override
public ProgressStatusEvent readFrom(final InputStream is, final String contentType) throws IOException {
try (JsonParser jp = factory.createJsonParser(is)) {
// sorounding object
JsonToken token = jp.nextToken();
// Name progress-status-event
jp.nextToken();
JsonToken token2 = jp.nextToken();
if (token != JsonToken.START_OBJECT || token2 != JsonToken.START_OBJECT || !"progress-status-event".equals(jp.getCurrentName())) {
throw new IOException("Not expected type (progress-status-event) but (" + jp.getCurrentName() + ")");
}
return readProgressStatusEvent(jp);
}
}
use of com.fasterxml.jackson.core.JsonToken in project openhab1-addons by openhab.
the class JsonWeatherParser method handleToken.
/**
* Iterates through the JSON structure and collects weather data.
*/
private void handleToken(JsonParser jp, String property, Weather weather) throws Exception {
JsonToken token = jp.getCurrentToken();
String prop = PropertyResolver.add(property, jp.getCurrentName());
if (token.isStructStart()) {
boolean isObject = token == JsonToken.START_OBJECT || token == JsonToken.END_OBJECT;
Weather forecast = !isObject ? weather : startIfForecast(weather, prop);
while (!jp.nextValue().isStructEnd()) {
handleToken(jp, prop, forecast);
}
if (isObject) {
endIfForecast(weather, forecast, prop);
}
} else if (token != null) {
try {
setValue(weather, prop, jp.getValueAsString());
} catch (Exception ex) {
logger.error("Error setting property '{}' with value '{}' ({})", prop, jp.getValueAsString(), ex.getMessage());
}
}
}
use of com.fasterxml.jackson.core.JsonToken in project moco by dreamhead.
the class LatencyContainerDeserializer method deserialize.
@Override
public LatencyContainer deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
JsonToken currentToken = jp.getCurrentToken();
if (currentToken == JsonToken.VALUE_NUMBER_INT) {
return LatencyContainer.latency(jp.getLongValue());
}
if (currentToken == JsonToken.START_OBJECT) {
jp.nextToken();
InternalLatencyContainer container = get(jp.readValuesAs(InternalLatencyContainer.class), 0);
return LatencyContainer.latencyWithUnit(container.duration, TimeUnit.valueOf(container.unit.toUpperCase() + 'S'));
}
return (LatencyContainer) ctxt.handleUnexpectedToken(LatencyContainer.class, jp);
}
Aggregations