diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/metadatavalidator/CsdlTypeValidator.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/metadatavalidator/CsdlTypeValidator.java index b85dfa678..fbb28d006 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/metadatavalidator/CsdlTypeValidator.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/metadatavalidator/CsdlTypeValidator.java @@ -125,12 +125,14 @@ public class CsdlTypeValidator { baseTypeFQName = validateCsdlEntityTypeWithAlias(baseTypeFQName); } baseEntityType = csdlEntityTypesMap.get(baseTypeFQName); - if (baseEntityType.getKey() != null) { - break; - } else if (baseEntityType != null && baseEntityType.getBaseType() != null) { - baseTypeFQName = baseEntityType.getBaseTypeFQN(); - } else if (baseEntityType.getBaseType() == null) { - break; + if (baseEntityType != null) { + if (baseEntityType.getKey() != null) { + break; + } else if (baseEntityType.getBaseType() != null) { + baseTypeFQName = baseEntityType.getBaseTypeFQN(); + } else if (baseEntityType.getBaseType() == null) { + break; + } } } return baseEntityType; @@ -149,16 +151,18 @@ public class CsdlTypeValidator { baseTypeFQName = validateCsdlEntityTypeWithAlias(baseTypeFQName); } baseEntityType = csdlEntityTypesMap.get(baseTypeFQName); - if (baseEntityType.getNavigationProperty(navBindingProperty) != null) { - break; - } else if (baseEntityType != null && baseEntityType.getBaseType() != null) { - baseTypeFQName = baseEntityType.getBaseTypeFQN(); - } else if (baseEntityType.getBaseType() == null) { - break; + if (baseEntityType != null) { + if (baseEntityType.getNavigationProperty(navBindingProperty) != null) { + break; + } else if (baseEntityType.getBaseType() != null) { + baseTypeFQName = baseEntityType.getBaseTypeFQN(); + } else if (baseEntityType.getBaseType() == null) { + break; + } } } if (baseEntityType == null) { - throw new RuntimeException("Entity TYpe is null with fully qualified name:" + baseTypeFQName); + throw new RuntimeException("Entity Type is null with fully qualified name:" + baseTypeFQName); } return baseEntityType.getNavigationProperty(navBindingProperty); } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/EntityTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/EntityTest.java index 52e8e706e..d80846b39 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/EntityTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/EntityTest.java @@ -404,17 +404,4 @@ public class EntityTest extends AbstractTest { assertTrue(property.isPrimitive()); assertEquals(property.getValueType(), ValueType.PRIMITIVE); } - - @Test - public void testFindTypeInEdmEnabledClient() throws Exception { - final Edm edm = client.getReader().readMetadata(getClass().getResourceAsStream("metadata_TripInService.xml")); - assertNotNull(edm); - final InputStream input = getClass().getResourceAsStream("tripinServEntity.json"); - EdmEnabledODataClient edmClient = ODataClientFactory.getEdmEnabledClient(SERVICE_URI, ContentType.APPLICATION_JSON); - ClientEntity entity = edmClient.getBinder().getODataEntity( - edmClient.getDeserializer(ContentType.APPLICATION_JSON).toEntity(input)); - assertNotNull(entity); - assertEquals(entity.getTypeName().getFullQualifiedNameAsString(), - "Microsoft.OData.SampleService.Models.TripPin.Person"); - } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java index 249e82128..9e4d74a31 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java @@ -350,8 +350,8 @@ public class ODataJsonSerializer extends AbstractODataSerializer { * @return ascii representation of the entity id */ private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException { - if(entity.getId() == null) { - if(entity == null || entityType == null || entityType.getKeyPredicateNames() == null + if(entity != null && entity.getId() == null) { + if(entityType == null || entityType.getKeyPredicateNames() == null || name == null) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); }else{