All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dreamhead.moco.parser.deserializer.ReplayModifierContainerDeserializer Maven / Gradle / Ivy

Go to download

Moco is an easy setup stub framework, mainly focusing on testing and integration.

There is a newer version: 1.5.0
Show newest version
package com.github.dreamhead.moco.parser.deserializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.github.dreamhead.moco.parser.model.ReplayContainer;
import com.github.dreamhead.moco.parser.model.ReplayModifierContainer;
import com.github.dreamhead.moco.parser.model.ResponseSetting;

import java.io.IOException;

import static com.github.dreamhead.moco.util.Strings.strip;

public class ReplayModifierContainerDeserializer extends JsonDeserializer {
    @Override
    public final ReplayModifierContainer deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
        JsonToken currentToken = p.getCurrentToken();
        if (currentToken == JsonToken.VALUE_STRING) {
            return new ReplayModifierContainer(strip(p.getText()));
        }

        if (currentToken == JsonToken.START_OBJECT) {
            p.nextToken();
            ResponseSetting setting = p.readValueAs(ResponseSetting.class);
            return new ReplayModifierContainer(setting);
        }

        return (ReplayModifierContainer) ctxt.handleUnexpectedToken(ReplayContainer.class, p);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy