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

项目: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);
    }
}
项目: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    文件: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);
            }
        }
    }
}