Skip to content

Commit

Permalink
Fix for issue #612
Browse files Browse the repository at this point in the history
  • Loading branch information
praries880 committed May 24, 2019
1 parent 5b613bc commit 1ed95dc
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ static SimpleModule getModule(ObjectMapper mapper) {

@Override
public CloudError deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
p.setCodec(mapper);
JsonNode errorNode = p.readValueAsTree();

if (errorNode == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.microsoft.azure;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.microsoft.azure.serializer.AzureJacksonAdapter;
import com.microsoft.rest.protocol.SerializerAdapter;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;

public class AzureAsyncOperationDeserializerTests {
@Test
public void DeserializeLROResult() throws IOException {
SerializerAdapter<ObjectMapper> serializerAdapter = new AzureJacksonAdapter();

String bodyString =
"{" +
" \"name\":\"1431219a-acad-4d70-9a17-f8b7a5a143cb\",\"status\":\"InProgress\"" +
"}";

AzureAsyncOperation asyncOperation = serializerAdapter.deserialize(bodyString, AzureAsyncOperation.class);

Assert.assertEquals("InProgress", asyncOperation.status());
Assert.assertEquals(null, asyncOperation.getError());

Exception e = null;
asyncOperation = null;
bodyString =
"{" +
" \"name\":\"1431219a-acad-4d70-9a17-f8b7a5a143cb\",\"status\":\"InProgress\"," +
" \"error\":{" +
" }" +
"}";
try {
asyncOperation = serializerAdapter.deserialize(bodyString, AzureAsyncOperation.class);
} catch (Exception ex) {
e = ex;
}

Assert.assertNull(e);
Assert.assertEquals("InProgress", asyncOperation.status());
CloudError error = asyncOperation.getError();
Assert.assertNotNull(error);
Assert.assertNull(error.message());
Assert.assertNull(error.code());

asyncOperation = null;
bodyString =
"{" +
" \"name\":\"1431219a-acad-4d70-9a17-f8b7a5a143cb\",\"status\":\"InProgress\"," +
" \"error\":{" +
" \"code\":\"None\",\"message\":null,\"target\":\"e1a19fd1-8110-470a-a82f-9f789c2b2917\"" +
" }" +
"}";

asyncOperation = serializerAdapter.deserialize(bodyString, AzureAsyncOperation.class);
Assert.assertEquals("InProgress", asyncOperation.status());
error = asyncOperation.getError();
Assert.assertNotNull(error);
Assert.assertEquals("None", error.code());
Assert.assertNull(error.message());
Assert.assertEquals("e1a19fd1-8110-470a-a82f-9f789c2b2917", error.target());
}
}

0 comments on commit 1ed95dc

Please sign in to comment.