Java 类com.amazonaws.transform.JsonUnmarshallerContext 实例源码

项目:ibm-cos-sdk-java    文件:JsonResponseHandler.java   
/**
 * Constructs a new response handler that will use the specified JSON unmarshaller to unmarshall
 * the service response and uses the specified response element path to find the root of the
 * business data in the service's response.
 * @param responseUnmarshaller    The JSON unmarshaller to use on the response.
 * @param simpleTypeUnmarshallers List of unmarshallers to be used for scalar types.
 * @param customTypeMarshallers   List of custom unmarshallers to be used for special types.
 * @param jsonFactory             the json factory to be used for parsing the response.
 */
public JsonResponseHandler(Unmarshaller<T, JsonUnmarshallerContext> responseUnmarshaller,
                           Map<Class<?>, Unmarshaller<?, JsonUnmarshallerContext>> simpleTypeUnmarshallers,
                           Map<UnmarshallerType, Unmarshaller<?, JsonUnmarshallerContext>> customTypeMarshallers,
                           JsonFactory jsonFactory, boolean needsConnectionLeftOpen,
                           boolean isPayloadJson) {
    /*
     * Even if the invoked operation just returns null, we still need an
     * unmarshaller to run so we can pull out response metadata.
     *
     * We might want to pass this in through the client class so that we
     * don't have to do this check here.
     */
    this.responseUnmarshaller =
            responseUnmarshaller != null ? responseUnmarshaller : new VoidJsonUnmarshaller<T>();

    this.needsConnectionLeftOpen = needsConnectionLeftOpen;
    this.isPayloadJson = isPayloadJson;

    this.simpleTypeUnmarshallers = ValidationUtils.assertNotNull(simpleTypeUnmarshallers, "simple type unmarshallers");
    this.customTypeMarshallers = ValidationUtils.assertNotNull(customTypeMarshallers, "custom type marshallers");
    this.jsonFactory = ValidationUtils.assertNotNull(jsonFactory, "JSONFactory");
}
项目:aws-hal-client-java    文件:JsonUnmarshallerUtil.java   
static Object getObjectForToken(JsonToken token, JsonUnmarshallerContext context)
        throws IOException {
    switch (token) {
    case VALUE_STRING:
        return context.getJsonParser().getText();
    case VALUE_NUMBER_FLOAT:
    case VALUE_NUMBER_INT:
        return context.getJsonParser().getNumberValue();
    case VALUE_FALSE:
        return Boolean.FALSE;
    case VALUE_TRUE:
        return Boolean.TRUE;
    case VALUE_NULL:
        return null;
    default:
        throw new RuntimeException("We expected a VALUE token but got: " + token);
    }
}
项目:aws-hal-client-java    文件:HalJsonListUnmarshaller.java   
@Override
public List<Object> unmarshall(JsonUnmarshallerContext context)
        throws Exception {
    List<Object> list = new ArrayList<>();
    JsonToken token = context.getCurrentToken();

    while (token != null && token != JsonToken.END_ARRAY) {
        if (token.isScalarValue()) {
            list.add(JsonUnmarshallerUtil.getObjectForToken(token, context));
        } else if (token == JsonToken.START_OBJECT) {
            context.nextToken();
            list.add(HalJsonMapUnmarshaller.getInstance().unmarshall(context));
        } else if (token == JsonToken.START_ARRAY) {
            context.nextToken();
            list.add(HalJsonListUnmarshaller.getInstance().unmarshall(context));
        }

        token = context.nextToken();
    }

    return list;
}
项目:aws-hal-client-java    文件:HalJsonArrayUnmarshaller.java   
@Override
public List<T> unmarshall(JsonUnmarshallerContext context)
        throws Exception {
    List<T> list = new ArrayList<>();
    JsonToken token = context.getCurrentToken();

    while (token != null && token != END_ARRAY) {
        if (token == JsonToken.START_OBJECT) {
            list.add(itemUnmarshaller.unmarshall(context));
        }

        token = context.nextToken();
    }

    return list;
}
项目:apigateway-generic-java-sdk    文件:GenericApiGatewayClient.java   
GenericApiGatewayClient(ClientConfiguration clientConfiguration, String endpoint, Region region,
                        AWSCredentialsProvider credentials, String apiKey, AmazonHttpClient httpClient) {
    super(clientConfiguration);
    setRegion(region);
    setEndpoint(endpoint);
    this.credentials = credentials;
    this.apiKey = apiKey;
    this.signer = new AWS4Signer();
    this.signer.setServiceName(API_GATEWAY_SERVICE_NAME);
    this.signer.setRegionName(region.getName());

    final JsonOperationMetadata metadata = new JsonOperationMetadata().withHasStreamingSuccessResponse(false).withPayloadJson(false);
    final Unmarshaller<GenericApiGatewayResponse, JsonUnmarshallerContext> responseUnmarshaller = in -> new GenericApiGatewayResponse(in.getHttpResponse());
    this.responseHandler = SdkStructuredPlainJsonFactory.SDK_JSON_FACTORY.createResponseHandler(metadata, responseUnmarshaller);
    JsonErrorUnmarshaller defaultErrorUnmarshaller = new JsonErrorUnmarshaller(GenericApiGatewayException.class, null) {
        @Override
        public AmazonServiceException unmarshall(JsonNode jsonContent) throws Exception {
            return new GenericApiGatewayException(jsonContent.toString());
        }
    };
    this.errorResponseHandler = SdkStructuredPlainJsonFactory.SDK_JSON_FACTORY.createErrorResponseHandler(
            Collections.singletonList(defaultErrorUnmarshaller), null);

    if (httpClient != null) {
        super.client = httpClient;
    }
}
项目:ibm-cos-sdk-java    文件:SdkStructuredJsonFactoryImpl.java   
public SdkStructuredJsonFactoryImpl(JsonFactory jsonFactory,
                                    Map<Class<?>, Unmarshaller<?, JsonUnmarshallerContext>> unmarshallers,
                                    Map<UnmarshallerType, Unmarshaller<?, JsonUnmarshallerContext>> customTypeMarshallers) {
    this.jsonFactory = jsonFactory;
    this.unmarshallers = unmarshallers;
    this.customTypeMarshallers = customTypeMarshallers;
}
项目:ibm-cos-sdk-java    文件:SdkStructuredJsonFactoryImpl.java   
@Override
public <T> JsonResponseHandler<T> createResponseHandler(JsonOperationMetadata operationMetadata,
                                                        Unmarshaller<T, JsonUnmarshallerContext> responseUnmarshaller) {
    return new JsonResponseHandler(responseUnmarshaller, unmarshallers, customTypeMarshallers, jsonFactory,
                                   operationMetadata.isHasStreamingSuccessResponse(),
                                   operationMetadata.isPayloadJson());
}
项目:ibm-cos-sdk-java    文件:JsonUnmarshallerTest.java   
@Test
public void testSimpleMap() throws Exception {
    JsonUnmarshallerContext unmarshallerContext = setupUnmarshaller(SIMPLE_MAP, EMPTY_HEADERS);

    MapUnmarshaller<String, String> unmarshaller = new MapUnmarshaller<String, String>(
            SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance(),
            SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance());

    Map<String, String> map = unmarshaller.unmarshall(unmarshallerContext);
    assertTrue(map.size() == 2);
    assertEquals("value1", map.get("key1"));
    assertEquals("value2", map.get("key2"));
}
项目:ibm-cos-sdk-java    文件:JsonUnmarshallerTest.java   
@Test
public void testMapToList() throws Exception {
    JsonUnmarshallerContext unmarshallerContext = setupUnmarshaller(MAP_TO_LIST, EMPTY_HEADERS);

    MapUnmarshaller<String, List<String>> unmarshaller = new MapUnmarshaller<String, List<String>>(
            SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance(),
            new ListUnmarshaller<String>(SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance()));

    Map<String, List<String>> map = unmarshaller.unmarshall(unmarshallerContext);
    assertTrue(map.size() == 2);
    assertEquals(Arrays.asList(null, "value1"), map.get("key1"));
    assertEquals(Arrays.asList("value2"), map.get("key2"));
}
项目:ibm-cos-sdk-java    文件:JsonUnmarshallerTest.java   
@Test
public void testJsonValueStringInBody() throws Exception {
    JsonUnmarshallerContext unmarshallerContext = setupUnmarshaller(BASE_64_STRING_VALUE, EMPTY_HEADERS);

    MapUnmarshaller<String, String> unmarshaller = new MapUnmarshaller<String, String>(
            SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance(),
            SimpleTypeJsonUnmarshallers.JsonValueStringUnmarshaller.getInstance());

    Map<String, String> map = unmarshaller.unmarshall(unmarshallerContext);

    assertEquals("value1", map.get("key1"));
}
项目:ibm-cos-sdk-java    文件:JsonUnmarshallerTest.java   
@Test
public void testJsonValueStringInHeader() throws Exception {
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Header", "dG9EZWNvZGU=");
    JsonUnmarshallerContext context = setupUnmarshaller(BASE_64_STRING_VALUE, headers);

    context.setCurrentHeader("Header");
    String value = SimpleTypeJsonUnmarshallers.JsonValueStringUnmarshaller.getInstance().unmarshall(context);

    assertEquals("toDecode", value);
}
项目:ibm-cos-sdk-java    文件:JsonUnmarshallerTest.java   
private JsonUnmarshallerContext setupUnmarshaller(String body, Map<String, String> headers) throws Exception {
    HttpResponse httpResponse = new HttpResponse(null, null);

    for (Map.Entry<String, String> header : headers.entrySet()) {
        httpResponse.addHeader(header.getKey(), header.getValue());
    }

    JsonParser jsonParser = jsonFactory.createParser(new ByteArrayInputStream(body.getBytes()));
    return new JsonUnmarshallerContextImpl(jsonParser,
                                           SdkStructuredPlainJsonFactory.JSON_SCALAR_UNMARSHALLERS,
                                           SdkStructuredPlainJsonFactory.JSON_CUSTOM_TYPE_UNMARSHALLERS,
                                           httpResponse);
}
项目:WaterFlow    文件:TestUtil.java   
/**
 * Use SWF API to unmarshal a json document into a {@link DecisionTask}.
 * Note: json is expected to be in the native format used by SWF
 */
public static DecisionTask unmarshalDecisionTask(String json) {
    try {
        Unmarshaller<DecisionTask, JsonUnmarshallerContext> unmarshaller = new DecisionTaskJsonUnmarshaller();
        JsonParser parser = new JsonFactory().createParser(json);
        return unmarshaller.unmarshall(new JsonUnmarshallerContextImpl(parser));
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
项目:ivona-speechcloud-sdk-java    文件:IvonaSpeechCloudClient.java   
@Override
public ListVoicesResult listVoices(ListVoicesRequest listVoicesRequest) throws AmazonServiceException,
        AmazonClientException {

    ExecutionContext executionContext = createExecutionContext(listVoicesRequest);
    Request<ListVoicesRequest> request = ListVoicesRequestMarshallerFactory.getMarshaller(
            listVoicesRequest.getMethodType()).marshall(listVoicesRequest);
    Unmarshaller<ListVoicesResult, JsonUnmarshallerContext> unmarshaller = new ListVoicesResultJsonUnmarshaller();
    JsonResponseHandler<ListVoicesResult> responseHandler =
            new JsonResponseHandler<ListVoicesResult>(unmarshaller);
    Response<ListVoicesResult> response = invoke(request, responseHandler, executionContext);
    return response.getAwsResponse();
}
项目:ivona-speechcloud-sdk-java    文件:IvonaSpeechCloudClient.java   
@Override
public GetLexiconResult getLexicon(GetLexiconRequest getLexiconRequest)
        throws AmazonServiceException, AmazonClientException {

    ExecutionContext executionContext = createExecutionContext(getLexiconRequest);
    GetLexiconRequestMarshaller marshaller = new GetLexiconPostRequestMarshaller();
    Request<GetLexiconRequest> request = marshaller.marshall(getLexiconRequest);
    Unmarshaller<GetLexiconResult, JsonUnmarshallerContext> unmarshaller = new GetLexiconResultJsonUnmarshaller();
    JsonResponseHandler<GetLexiconResult> responseHandler = new JsonResponseHandler<GetLexiconResult>(unmarshaller);

    Response<GetLexiconResult> response = invoke(request, responseHandler, executionContext);
    return response.getAwsResponse();
}
项目:ivona-speechcloud-sdk-java    文件:IvonaSpeechCloudClient.java   
@Override
public ListLexiconsResult listLexicons() {
    ListLexiconsRequest listLexiconsRequest = new ListLexiconsRequest();
    ExecutionContext executionContext = createExecutionContext(listLexiconsRequest);
    ListLexiconsRequestMarshaller marshaller = new ListLexiconsPostRequestMarshaller();
    Request<ListLexiconsRequest> request = marshaller.marshall(listLexiconsRequest);
    Unmarshaller<ListLexiconsResult, JsonUnmarshallerContext> unmarshaller =
            new ListLexiconsResultJsonUnmarshaller();
    JsonResponseHandler<ListLexiconsResult> responseHandler =
            new JsonResponseHandler<ListLexiconsResult>(unmarshaller);

    Response<ListLexiconsResult> response = invoke(request, responseHandler, executionContext);
    return response.getAwsResponse();
}
项目:ivona-speechcloud-sdk-java    文件:ListLexiconsResultJsonUnmarshaller.java   
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;
}
项目:ivona-speechcloud-sdk-java    文件:GetLexiconResultJsonUnmarshaller.java   
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();
    }
    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;
}
项目:ivona-speechcloud-sdk-java    文件:ListVoicesResultJsonUnmarshaller.java   
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();
    }
    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;
}
项目:aws-hal-client-java    文件:HalJsonMapUnmarshaller.java   
@Override
public Map<String, Object> unmarshall(JsonUnmarshallerContext context)
        throws Exception {
    Map<String, Object> map = new HashMap<>();
    JsonToken token = context.getCurrentToken();

    while (token != null && token != JsonToken.END_OBJECT) {
        if (token == JsonToken.FIELD_NAME) {
            String property = context.readText();

            token = context.nextToken();
            if (token == JsonToken.START_OBJECT) {
                context.nextToken();
                map.put(property, HalJsonMapUnmarshaller.getInstance().unmarshall(context));
            } else if (token == JsonToken.START_ARRAY) {
                context.nextToken();
                map.put(property, HalJsonListUnmarshaller.getInstance().unmarshall(context));
            } else {
                map.put(property, JsonUnmarshallerUtil.getObjectForToken(token, context));
            }
        }

        token = context.nextToken();
    }

    return map;
}
项目:aws-hal-client-java    文件:HalJsonLinkUnmarshaller.java   
@Override
public HalLink unmarshall(JsonUnmarshallerContext context)
        throws Exception {
    HalLink halLink = new HalLink();
    JsonToken token = context.getCurrentToken();

    while (token != null && token != JsonToken.END_OBJECT) {
        if (token == JsonToken.FIELD_NAME) {
            if (context.testExpression("href")) {
                context.nextToken();
                halLink.setHref(context.readText());
            } else if (context.testExpression("name")) {
                context.nextToken();
                halLink.setName(context.readText());
            } else if (context.testExpression("title")) {
                context.nextToken();
                halLink.setTitle(context.readText());
            } else if (context.testExpression("templated")) {
                context.nextToken();
                halLink.setTemplated(Boolean.valueOf(context.readText()));
            } else if (context.testExpression("deprecation")) {
                context.nextToken();
                halLink.setDeprecation(context.readText());
            } else {
                // Ignore this.  Likely one of hreflang, profile, type
                context.nextToken();
            }
        }

        token = context.nextToken();
    }

    return halLink;
}
项目:aws-hal-client-java    文件:HalJsonCurieUnmarshaller.java   
@Override
public HalLink unmarshall(JsonUnmarshallerContext context)
        throws Exception {
    HalLink halLink = new HalLink();
    JsonToken token = context.getCurrentToken();

    // Ignore curies for now.
    while (token != null && token != JsonToken.END_OBJECT) {
        token = context.nextToken();
    }

    return halLink;
}
项目:aws-hal-client-java    文件:OptionalJsonResponseHandler.java   
@Override
protected void registerAdditionalMetadataExpressions(JsonUnmarshallerContext unmarshallerContext) {
    Map<String, String> headers = unmarshallerContext.getHttpResponse().getHeaders();

    if (headers.containsKey("Location")) {
        location = headers.get("Location");
    } else if (headers.containsKey("location")) {
        location = headers.get("location");
    }
}
项目:aws-hal-client-java    文件:HalJsonLinksUnmarshaller.java   
@Override
public Map<String, HalLink> unmarshall(JsonUnmarshallerContext context)
        throws Exception {
    Map<String, HalLink> links = new LinkedHashMap<>();
    JsonToken token = context.getCurrentToken();

    while (token != null && token != JsonToken.END_OBJECT) {
        if (token == JsonToken.FIELD_NAME) {
            if (context.testExpression("curie")) {
                context.nextToken();
                HalJsonCurieUnmarshaller.getInstance().unmarshall(context);
            } else {
                String relation = context.readText();
                token = context.nextToken();

                if (token == JsonToken.START_ARRAY) {
                    List<HalLink> halLinks = new HalJsonArrayUnmarshaller<>(HalJsonLinkUnmarshaller.getInstance()).unmarshall(context);

                    int i = 0;
                    for (HalLink halLink : halLinks) {
                        links.put(relation + "_" + i++, halLink);
                    }
                } else {
                    links.put(relation, HalJsonLinkUnmarshaller.getInstance().unmarshall(context));
                }
            }
        }

        token = context.nextToken();
    }

    return links;
}
项目:aws-hal-client-java    文件:HalJsonResourceUnmarshaller.java   
@Override
public HalResource unmarshall(JsonUnmarshallerContext context)
        throws Exception {
    HalResource halResource = new HalResource();
    JsonToken token = context.getCurrentToken();

    if (token == null) {
        token = context.nextToken();
    }

    while (token != null && token != JsonToken.END_OBJECT) {
        if (token == JsonToken.FIELD_NAME) {
            if (context.testExpression("_links")) {
                context.nextToken();
                halResource.setLinks(HalJsonLinksUnmarshaller.getInstance().unmarshall(context));
            } else if (context.testExpression("_embedded")) {
                context.nextToken();
                halResource.setEmbedded(HalJsonEmbeddedUnmarshaller.getInstance().unmarshall(context));
            } else {
                String property = context.readText();

                token = context.nextToken();

                if (token == JsonToken.START_OBJECT) {
                    context.nextToken();
                    halResource.addProperty(property, HalJsonMapUnmarshaller.getInstance().unmarshall(context));
                } else if (token == JsonToken.START_ARRAY) {
                    context.nextToken();
                    halResource.addProperty(property, HalJsonListUnmarshaller.getInstance().unmarshall(context));
                } else {
                    halResource.addProperty(property, JsonUnmarshallerUtil.getObjectForToken(token, context));
                }
            }
        }

        token = context.nextToken();
    }

    return halResource;
}
项目:aws-hal-client-java    文件:HalJsonResourceUnmarshallerTest.java   
private HalResource parseHalResourceFromClasspath(String classpathFile)
        throws Exception {
    InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(classpathFile);
    JsonParser jsonParser = new JsonFactory().createJsonParser(inputStream);
    JsonUnmarshallerContext jsonUnmarshallerContext = new JsonUnmarshallerContextImpl(jsonParser);

    return HalJsonResourceUnmarshaller.getInstance().unmarshall(jsonUnmarshallerContext);
}
项目:ibm-cos-sdk-java    文件:SdkJsonProtocolFactory.java   
/**
 * Returns the response handler to be used for handling a successful response.
 *
 * @param operationMetadata Additional context information about an operation to create the appropriate response handler.
 */
public <T> HttpResponseHandler<AmazonWebServiceResponse<T>> createResponseHandler(
        JsonOperationMetadata operationMetadata,
        Unmarshaller<T, JsonUnmarshallerContext> responseUnmarshaller) {
    return getSdkFactory().createResponseHandler(operationMetadata, responseUnmarshaller);
}
项目:ibm-cos-sdk-java    文件:SdkStructuredIonFactory.java   
private SdkStructuredIonFactory(IonWriterBuilder builder) {
    super(JSON_FACTORY, UNMARSHALLERS,
          Collections.<JsonUnmarshallerContext.UnmarshallerType, Unmarshaller<?, JsonUnmarshallerContext>>emptyMap());
    this.builder = builder;
}
项目:ibm-cos-sdk-java    文件:JsonResponseHandler.java   
/**
 * @see HttpResponseHandler#handle(HttpResponse)
 */
public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception {
    log.trace("Parsing service response JSON");

    String CRC32Checksum = response.getHeaders().get("x-amz-crc32");

    JsonParser jsonParser = null;

    if (shouldParsePayloadAsJson()) {
        jsonParser = jsonFactory.createParser(response.getContent());
    }

    try {
        AmazonWebServiceResponse<T> awsResponse = new AmazonWebServiceResponse<T>();
        JsonUnmarshallerContext unmarshallerContext = new JsonUnmarshallerContextImpl(
                jsonParser, simpleTypeUnmarshallers, customTypeMarshallers, response);
        registerAdditionalMetadataExpressions(unmarshallerContext);

        T result = responseUnmarshaller.unmarshall(unmarshallerContext);

        // Make sure we read all the data to get an accurate CRC32 calculation.
        // See https://github.com/aws/aws-sdk-java/issues/1018
        if (shouldParsePayloadAsJson() && response.getContent() != null) {
            IOUtils.drainInputStream(response.getContent());
        }

        if (CRC32Checksum != null) {
            long serverSideCRC = Long.parseLong(CRC32Checksum);
            long clientSideCRC = response.getCRC32Checksum();
            if (clientSideCRC != serverSideCRC) {
                throw new CRC32MismatchException(
                        "Client calculated crc32 checksum didn't match that calculated by server side");
            }
        }

        awsResponse.setResult(result);

        Map<String, String> metadata = unmarshallerContext.getMetadata();
        metadata.put(ResponseMetadata.AWS_REQUEST_ID,
                     response.getHeaders().get(X_AMZN_REQUEST_ID_HEADER));
        awsResponse.setResponseMetadata(new ResponseMetadata(metadata));

        log.trace("Done parsing service response");
        return awsResponse;
    } finally {
        if (shouldParsePayloadAsJson()) {
            try {
                jsonParser.close();
            } catch (IOException e) {
                log.warn("Error closing json parser", e);
            }
        }
    }
}
项目:ivona-speechcloud-sdk-java    文件:LexiconJsonUnmarshaller.java   
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();
    }
    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;
}
项目:ivona-speechcloud-sdk-java    文件:VoiceJsonUnmarshaller.java   
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;
    }
项目:aws-hal-client-java    文件:OptionalJsonResponseHandler.java   
OptionalJsonResponseHandler(Unmarshaller<T, JsonUnmarshallerContext> responseUnmarshaller) {
    super(responseUnmarshaller);
}
项目:aws-hal-client-java    文件:HalJsonArrayUnmarshaller.java   
public HalJsonArrayUnmarshaller(Unmarshaller<T, JsonUnmarshallerContext> itemUnmarshaller) {
    this.itemUnmarshaller = itemUnmarshaller;
}
项目:ibm-cos-sdk-java    文件:SdkStructuredJsonFactory.java   
/**
 * Returns the response handler to be used for handling a successfull response.
 *
 * @param operationMetadata Additional context information about an operation to create the
 *                          appropriate response handler.
 */
<T> JsonResponseHandler<T> createResponseHandler(JsonOperationMetadata operationMetadata,
                                                 Unmarshaller<T, JsonUnmarshallerContext> responseUnmarshaller);
项目:ibm-cos-sdk-java    文件:JsonResponseHandler.java   
/**
 * Hook for subclasses to override in order to collect additional metadata from service
 * responses.
 *
 * @param unmarshallerContext
 *            The unmarshaller context used to configure a service's response
 *            data.
 */
protected void registerAdditionalMetadataExpressions(
        JsonUnmarshallerContext unmarshallerContext) {
}