package com.brilliance.isc.common.json;

import com.brilliance.mda.runtime.mda.IStream;
import com.brilliance.mda.runtime.mda.impl.StreamImpl;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;

import java.io.IOException;

public class IStreamDeserializer extends JsonDeserializer<IStream> {

    @Override
    public IStream deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        JsonNode rootNode = jsonParser.getCodec().readTree(jsonParser);
        if (rootNode != null) {
            String value = rootNode.asText();
            IStream yourType = new StreamImpl();;
            yourType.setValue(value);
            return yourType;
        }
        return null;
    }
}
