diff --git a/client-runtime/src/main/java/com/microsoft/rest/serializer/FlatteningDeserializer.java b/client-runtime/src/main/java/com/microsoft/rest/serializer/FlatteningDeserializer.java index 7c14ed01cb..b101620d80 100644 --- a/client-runtime/src/main/java/com/microsoft/rest/serializer/FlatteningDeserializer.java +++ b/client-runtime/src/main/java/com/microsoft/rest/serializer/FlatteningDeserializer.java @@ -118,6 +118,9 @@ public Object deserialize(JsonParser jp, DeserializationContext cxt) throws IOEx // Json object this method is called to handle. // JsonNode currentJsonNode = mapper.readTree(jp); + if (currentJsonNode.isNull()){ + currentJsonNode = mapper.getNodeFactory().objectNode(); + } final Class tClass = this.defaultDeserializer.handledType(); for (Class c : TypeToken.of(tClass).getTypes().classes().rawTypes()) { if (c.isAssignableFrom(Object.class)) { diff --git a/client-runtime/src/test/java/com/microsoft/rest/FlatteningSerializerTests.java b/client-runtime/src/test/java/com/microsoft/rest/FlatteningSerializerTests.java index 40292d9821..192ea5d2e4 100644 --- a/client-runtime/src/test/java/com/microsoft/rest/FlatteningSerializerTests.java +++ b/client-runtime/src/test/java/com/microsoft/rest/FlatteningSerializerTests.java @@ -59,6 +59,32 @@ public void canSerializeMapKeysWithDotAndSlash() throws Exception { Assert.assertEquals("{\"teacher\":{\"students\":{\"af.B/D\":{},\"af.B/C\":{}}},\"tags\":{\"foo.aa\":\"bar\",\"x.y\":\"zz\"},\"properties\":{\"name\":\"school1\"}}", serialized); } + /** + * Validates decoding and encoding of a type with type id containing dot and no additional properties + * For decoding and encoding base type will be used. + * + * @throws IOException + */ + @Test + public void canHandleTypeWithTypeIdContainingDotAndNoProperties() throws IOException { + JacksonAdapter adapter = new JacksonAdapter(); + + String rabbitSerialized = "{\"@odata.type\":\"#Favourite.Pet.RabbitWithTypeIdContainingDot\"}"; + String shelterSerialized = "{\"properties\":{\"animalsInfo\":[{\"animal\":{\"@odata.type\":\"#Favourite.Pet.RabbitWithTypeIdContainingDot\"}},{\"animal\":{\"@odata.type\":\"#Favourite.Pet.RabbitWithTypeIdContainingDot\"}}]}}"; + + AnimalWithTypeIdContainingDot rabbitDeserialized = adapter.deserialize(rabbitSerialized, AnimalWithTypeIdContainingDot.class); + Assert.assertTrue(rabbitDeserialized instanceof RabbitWithTypeIdContainingDot); + Assert.assertNotNull(rabbitDeserialized); + + AnimalShelter shelterDeserialized = adapter.deserialize(shelterSerialized, AnimalShelter.class); + Assert.assertTrue(shelterDeserialized instanceof AnimalShelter); + Assert.assertEquals(2, shelterDeserialized.animalsInfo().size()); + for (FlattenableAnimalInfo animalInfo: shelterDeserialized.animalsInfo()) { + Assert.assertTrue(animalInfo.animal() instanceof RabbitWithTypeIdContainingDot); + Assert.assertNotNull(animalInfo.animal()); + } + } + /** * Validates that decoding and encoding of a type with type id containing dot and can be done. * For decoding and encoding base type will be used.