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

com.ksc.kls.model.transform.StreamDurationsDataUnmarshaller Maven / Gradle / Ivy

Go to download

The KSC SDK for Java - kls module holds the classes that is used by the individual service clients to interact with KSC Web Services. Users need to depend on live-java-sdk artifact for accessing individual client classes.

The newest version!
package com.ksc.kls.model.transform;

import com.fasterxml.jackson.core.JsonToken;
import com.ksc.kls.model.ListStreamDurations;
import com.ksc.kls.model.ParamConstant;
import com.ksc.kls.model.StreamDurationsDetail;
import com.ksc.transform.JsonUnmarshallerContext;
import com.ksc.transform.ListUnmarshaller;
import com.ksc.transform.Unmarshaller;

import static com.fasterxml.jackson.core.JsonToken.*;

/**
 * Created by yangfan on 2017/5/5.
 */
public class StreamDurationsDataUnmarshaller  implements Unmarshaller {

    private static StreamDurationsDataUnmarshaller instance;

    public synchronized static StreamDurationsDataUnmarshaller getInstance() {
        if (instance == null) {
            instance = new StreamDurationsDataUnmarshaller();
        }
        return instance;
    }

    @Override
    public ListStreamDurations unmarshall(JsonUnmarshallerContext context) throws Exception {
        ListStreamDurations result = new ListStreamDurations();
        int originalDepth = context.getCurrentDepth();
        String currentParentElement = context.getCurrentParentElement();
        int targetDepth = originalDepth + 1;


        JsonToken token = context.getCurrentToken();
        if (token == null)
            token = context.nextToken();
        if (token == VALUE_NULL)
            return null;

        while (true) {
            if (token == null)
                break;


            if (token == FIELD_NAME || token == START_OBJECT) {
                if (context.testExpression(ParamConstant.APP,targetDepth)) {
                    context.nextToken();
                    result.setApp(context.getUnmarshaller(String.class).unmarshall(context));
                } else if (context.testExpression(ParamConstant.COUNT,targetDepth)) {
                    context.nextToken();
                    result.setCount(context.getUnmarshaller(Integer.class).unmarshall(context));
                } else if (context.testExpression(ParamConstant.PUBDOMAIN,targetDepth)) {
                    context.nextToken();
                    result.setPubdomain(context.getUnmarshaller(String.class).unmarshall(context));
                } else if (context.testExpression(ParamConstant.RETCODE,targetDepth)) {
                    context.nextToken();
                    result.setRetCode(context.getUnmarshaller(Integer.class).unmarshall(context));
                } else if (context.testExpression(ParamConstant.RETMSG,targetDepth)) {
                    context.nextToken();
                    result.setRetMsg(context.getUnmarshaller(String.class).unmarshall(context));
                } else if (context.testExpression(ParamConstant.UNIQUE_NAME,targetDepth)) {
                    context.nextToken();
                    result.setUniqueName(context.getUnmarshaller(String.class).unmarshall(context));
                } else if (context.testExpression(ParamConstant.RESULT,targetDepth)) {
                    context.nextToken();
                    result.setResult(new ListUnmarshaller(StreamDurationsDetailUnmarshaller.getInstance()).unmarshall(context));
                }
            } else if (token == END_ARRAY || token == END_OBJECT) {
                if (context.getLastParsedParentElement() == null
                        || context.getLastParsedParentElement().equals(currentParentElement)) {
                    if (context.getCurrentDepth() <= originalDepth)
                        break;
                }
            }
            token = context.nextToken();
        }
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy