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(); } 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; }
public DeleteItemRequest unmarshall(JsonUnmarshallerContext context) throws Exception { DeleteItemRequest request = new DeleteItemRequest(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) token = context.nextToken(); while (true) { if (token == null) break; if (token == JsonToken.FIELD_NAME || token == JsonToken.START_OBJECT) { if (context.testExpression("TableName", targetDepth)) { context.nextToken(); request.setTableName( SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); } if (context.testExpression("Key", targetDepth)) { request.setKey( new MapUnmarshaller<String, AttributeValue>( SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance(), AttributeValueJsonUnmarshaller.getInstance()) .unmarshall(context)); } if (context.testExpression("Expected", targetDepth)) { request.setExpected( new MapUnmarshaller<String, ExpectedAttributeValue>( SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance(), ExpectedAttributeValueJsonUnmarshaller.getInstance()) .unmarshall(context)); } if (context.testExpression("ReturnValues", targetDepth)) { context.nextToken(); request.setReturnValues( SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); } } else if (token == JsonToken.END_ARRAY || token == JsonToken.END_OBJECT) { if (context.getCurrentDepth() <= originalDepth) break; } token = context.nextToken(); } return request; }
@Test public void testStringJsonUnmarshaller() throws Exception { StringWriter sw = new StringWriter(); AwsJsonWriter jw = JsonUtils.getJsonWriter(sw); jw.beginObject(); jw.name("s"); jw.value("String"); jw.endObject(); String json = sw.toString(); StringReader sr = new StringReader(json); AwsJsonReader jr = JsonUtils.getJsonReader(sr); JsonUnmarshallerContext context = new JsonUnmarshallerContext(jr); context.getReader().beginObject(); context.getReader().nextName(); SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller sUnmarshaller = SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance(); assertEquals(sUnmarshaller.unmarshall(context), "String"); }
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(); } 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; }