Example usage for com.amazonaws.transform JsonUnmarshallerContext testExpression

List of usage examples for com.amazonaws.transform JsonUnmarshallerContext testExpression

Introduction

In this page you can find the example usage for com.amazonaws.transform JsonUnmarshallerContext testExpression.

Prototype

public boolean testExpression(String expression, int stackDepth) 

Source Link

Document

Tests the specified expression (a JSON field name) against the current position in the JSON document being parsed, and restricts the expression to matching at the specified stack depth.

Usage

From source file:com.ivona.services.tts.model.transform.lexicons.GetLexiconResultJsonUnmarshaller.java

License:Open Source License

public GetLexiconResult unmarshall(JsonUnmarshallerContext context) throws Exception {
    GetLexiconResult getLexiconResult = new GetLexiconResult();

    int originalDepth = context.getCurrentDepth();
    String currentParentElement = context.getCurrentParentElement();
    int targetDepth = originalDepth + 1;

    JsonToken token = context.getCurrentToken();
    if (token == null) {
        token = context.nextToken();//from   w ww. j  a  v  a 2 s  .c  om
    }
    if (token == VALUE_NULL) {
        return null;
    }

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

        if (token == FIELD_NAME || token == START_OBJECT) {
            if (context.testExpression(JSON_KEY_LEXICON, targetDepth)) {
                context.nextToken();
                getLexiconResult.setLexicon(LexiconJsonUnmarshaller.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 getLexiconResult;
}

From source file:com.ivona.services.tts.model.transform.lexicons.LexiconJsonUnmarshaller.java

License:Open Source License

public Lexicon unmarshall(JsonUnmarshallerContext context) throws Exception {
    Lexicon lexicon = new Lexicon();

    int originalDepth = context.getCurrentDepth();
    String currentParentElement = context.getCurrentParentElement();
    int targetDepth = originalDepth + 1;

    JsonToken token = context.getCurrentToken();
    if (token == null) {
        token = context.nextToken();/*w  ww. j  ava2  s .com*/
    }
    if (token == VALUE_NULL) {
        return null;
    }

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

        if (token == FIELD_NAME || token == START_OBJECT) {
            if (context.testExpression(JSON_KEY_NAME, targetDepth)) {
                context.nextToken();
                lexicon.setName(
                        SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context));
            }
            if (context.testExpression(JSON_KEY_CONTENTS, targetDepth)) {
                context.nextToken();
                lexicon.setContents(
                        SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.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 lexicon;
}

From source file:com.ivona.services.tts.model.transform.lexicons.ListLexiconsResultJsonUnmarshaller.java

License:Open Source License

public ListLexiconsResult unmarshall(JsonUnmarshallerContext context) throws Exception {
    ListLexiconsResult listLexiconsResult = new ListLexiconsResult();

    int originalDepth = context.getCurrentDepth();
    String currentParentElement = context.getCurrentParentElement();
    int targetDepth = originalDepth + 1;

    JsonToken token = context.getCurrentToken();
    if (token == null) {
        token = context.nextToken();//from  www.  j  av a 2  s  . c o m
    }
    if (token == VALUE_NULL) {
        return null;
    }

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

        if (token == FIELD_NAME || token == START_OBJECT) {
            if (context.testExpression(JSON_KEY_LEXICONS, targetDepth)) {
                listLexiconsResult.setLexiconNames(new ListUnmarshaller<String>(
                        SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.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 listLexiconsResult;
}

From source file:com.ivona.services.tts.model.transform.listvoices.ListVoicesResultJsonUnmarshaller.java

License:Open Source License

public ListVoicesResult unmarshall(JsonUnmarshallerContext context) throws Exception {
    ListVoicesResult listVoicesResult = new ListVoicesResult();

    int originalDepth = context.getCurrentDepth();
    String currentParentElement = context.getCurrentParentElement();
    int targetDepth = originalDepth + 1;

    JsonToken token = context.getCurrentToken();
    if (token == null) {
        token = context.nextToken();/*from w w  w. ja  v  a2 s .  c o m*/
    }
    if (token == VALUE_NULL) {
        return null;
    }

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

        if (token == FIELD_NAME || token == START_OBJECT) {
            if (context.testExpression(JSON_KEY_VOICES, targetDepth)) {
                listVoicesResult.setVoices(
                        new ListUnmarshaller<Voice>(VoiceJsonUnmarshaller.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 listVoicesResult;
}

From source file:com.ivona.services.tts.model.transform.listvoices.VoiceJsonUnmarshaller.java

License:Open Source License

public Voice unmarshall(JsonUnmarshallerContext context) throws Exception {

    Voice voice = new Voice();

    int originalDepth = context.getCurrentDepth();
    String currentParentElement = context.getCurrentParentElement();
    int targetDepth = originalDepth + 1;

    JsonToken token = context.getCurrentToken();
    if (token == null) {
        token = context.nextToken();/*from w  w  w . j  a  v a 2 s.c  o m*/
    }
    if (token == VALUE_NULL) {
        return null;
    }

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

        if (token == FIELD_NAME || token == START_OBJECT) {
            if (context.testExpression(JSON_KEY_NAME, targetDepth)) {
                context.nextToken();
                voice.setName(
                        SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context));
            }
            if (context.testExpression(JSON_KEY_LANGUAGE, targetDepth)) {
                context.nextToken();
                voice.setLanguage(
                        SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context));
            }
            if (context.testExpression(JSON_KEY_GENDER, targetDepth)) {
                context.nextToken();
                voice.setGender(
                        SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.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 voice;
}