Search in sources :

Example 1 with LatencyContainer

use of com.github.dreamhead.moco.parser.model.LatencyContainer 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);
}
Also used : LatencyContainer(com.github.dreamhead.moco.parser.model.LatencyContainer) JsonToken(com.fasterxml.jackson.core.JsonToken)

Aggregations

JsonToken (com.fasterxml.jackson.core.JsonToken)1 LatencyContainer (com.github.dreamhead.moco.parser.model.LatencyContainer)1