Search in sources :

Example 6 with JsonUnmarshallerContext

use of com.amazonaws.transform.JsonUnmarshallerContext in project aws-sdk-android by aws-amplify.

the class JsonUnmarshallerTest method testSimpleMap.

@Test
public void testSimpleMap() throws Exception {
    JsonUnmarshallerContext unmarshallerContext = setupUnmarshaller(SIMPLE_MAP);
    MapUnmarshaller<String> unmarshaller = new MapUnmarshaller<String>(SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance());
    Map<String, String> map = unmarshaller.unmarshall(unmarshallerContext);
    assertTrue(map.size() == 2);
    assertEquals("value1", map.get("key1"));
    assertEquals("value2", map.get("key2"));
}
Also used : MapUnmarshaller(com.amazonaws.transform.MapUnmarshaller) JsonUnmarshallerContext(com.amazonaws.transform.JsonUnmarshallerContext) Test(org.junit.Test)

Example 7 with JsonUnmarshallerContext

use of com.amazonaws.transform.JsonUnmarshallerContext in project aws-sdk-android by aws-amplify.

the class InvalidContactFlowModuleExceptionUnmarshaller method unmarshall.

@Override
public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception {
    InvalidContactFlowModuleException e = (InvalidContactFlowModuleException) super.unmarshall(error);
    e.setErrorCode("InvalidContactFlowModuleException");
    final AwsJsonReader jsonReader = JsonUtils.getJsonReader(new StringReader(error.get("Problems")));
    e.setProblems(new ListUnmarshaller<ProblemDetail>(ProblemDetailJsonUnmarshaller.getInstance()).unmarshall(new JsonUnmarshallerContext(jsonReader)));
    return e;
}
Also used : InvalidContactFlowModuleException(com.amazonaws.services.connect.model.InvalidContactFlowModuleException) ListUnmarshaller(com.amazonaws.transform.ListUnmarshaller) StringReader(java.io.StringReader) JsonUnmarshallerContext(com.amazonaws.transform.JsonUnmarshallerContext) AwsJsonReader(com.amazonaws.util.json.AwsJsonReader)

Example 8 with JsonUnmarshallerContext

use of com.amazonaws.transform.JsonUnmarshallerContext in project aws-sdk-android by aws-amplify.

the class InvalidContactFlowExceptionUnmarshaller method unmarshall.

@Override
public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception {
    InvalidContactFlowException e = (InvalidContactFlowException) super.unmarshall(error);
    e.setErrorCode("InvalidContactFlowException");
    final AwsJsonReader jsonReader = JsonUtils.getJsonReader(new StringReader(error.get("problems")));
    e.setProblems(new ListUnmarshaller<ProblemDetail>(ProblemDetailJsonUnmarshaller.getInstance()).unmarshall(new JsonUnmarshallerContext(jsonReader)));
    return e;
}
Also used : ListUnmarshaller(com.amazonaws.transform.ListUnmarshaller) StringReader(java.io.StringReader) InvalidContactFlowException(com.amazonaws.services.connect.model.InvalidContactFlowException) JsonUnmarshallerContext(com.amazonaws.transform.JsonUnmarshallerContext) AwsJsonReader(com.amazonaws.util.json.AwsJsonReader)

Example 9 with JsonUnmarshallerContext

use of com.amazonaws.transform.JsonUnmarshallerContext in project aws-sdk-android by aws-amplify.

the class JsonUnmarshallerTest method testMapToList.

@Test
public void testMapToList() throws Exception {
    JsonUnmarshallerContext unmarshallerContext = setupUnmarshaller(MAP_TO_LIST);
    MapUnmarshaller<List<String>> unmarshaller = new MapUnmarshaller<List<String>>(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"));
}
Also used : MapUnmarshaller(com.amazonaws.transform.MapUnmarshaller) List(java.util.List) JsonUnmarshallerContext(com.amazonaws.transform.JsonUnmarshallerContext) Test(org.junit.Test)

Example 10 with JsonUnmarshallerContext

use of com.amazonaws.transform.JsonUnmarshallerContext in project aws-sdk-android by aws-amplify.

the class InvokeResultJsonUnmarshallerTest method testUnmarshall.

@Test
public void testUnmarshall() throws Exception {
    int statusCode = 299;
    String error = "error";
    String log = "a very long log";
    String content = "some content";
    HttpResponse response = HttpResponse.builder().statusCode(statusCode).statusCode(statusCode).header("X-Amz-Function-Error", error).header("X-Amz-Log-Result", log).content(new ByteArrayInputStream(content.getBytes(StringUtils.UTF8))).build();
    JsonUnmarshallerContext context = new JsonUnmarshallerContext(null, response);
    InvokeResultJsonUnmarshaller unmarshaller = InvokeResultJsonUnmarshaller.getInstance();
    InvokeResult result = unmarshaller.unmarshall(context);
    assertTrue("status code", statusCode == result.getStatusCode());
    assertEquals("error", error, result.getFunctionError());
    assertEquals("log", log, result.getLogResult());
    ByteBuffer payload = result.getPayload();
    assertArrayEquals("same payload", content.getBytes(StringUtils.UTF8), payload.array());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HttpResponse(com.amazonaws.http.HttpResponse) InvokeResult(com.amazonaws.services.lambda.model.InvokeResult) ByteBuffer(java.nio.ByteBuffer) JsonUnmarshallerContext(com.amazonaws.transform.JsonUnmarshallerContext) Test(org.junit.Test)

Aggregations

JsonUnmarshallerContext (com.amazonaws.transform.JsonUnmarshallerContext)11 Test (org.junit.Test)6 AwsJsonReader (com.amazonaws.util.json.AwsJsonReader)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 StringReader (java.io.StringReader)4 ListUnmarshaller (com.amazonaws.transform.ListUnmarshaller)3 Unmarshaller (com.amazonaws.transform.Unmarshaller)3 MapUnmarshaller (com.amazonaws.transform.MapUnmarshaller)2 InputStream (java.io.InputStream)2 CRC32 (java.util.zip.CRC32)2 AmazonWebServiceResponse (com.amazonaws.AmazonWebServiceResponse)1 ResponseMetadata (com.amazonaws.ResponseMetadata)1 HttpResponse (com.amazonaws.http.HttpResponse)1 CRC32MismatchException (com.amazonaws.internal.CRC32MismatchException)1 InvalidContactFlowException (com.amazonaws.services.connect.model.InvalidContactFlowException)1 InvalidContactFlowModuleException (com.amazonaws.services.connect.model.InvalidContactFlowModuleException)1 ValidationException (com.amazonaws.services.geo.model.ValidationException)1 InvokeResult (com.amazonaws.services.lambda.model.InvokeResult)1 CRC32ChecksumCalculatingInputStream (com.amazonaws.util.CRC32ChecksumCalculatingInputStream)1 IOException (java.io.IOException)1