-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OLINGO-1609] Fix issue in JSON deserializer
fix issue with multiple stream properties and metadata=full for deserialization
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
lib/client-core/src/test/java/org/apache/olingo/client/core/JsonDeserializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.olingo.client.core; | ||
|
||
import org.apache.olingo.client.api.data.ResWrap; | ||
import org.apache.olingo.client.api.domain.ClientEntity; | ||
import org.apache.olingo.client.api.domain.ClientLink; | ||
import org.apache.olingo.client.api.serialization.ODataDeserializerException; | ||
import org.apache.olingo.client.core.serialization.ClientODataDeserializerImpl; | ||
import org.apache.olingo.client.core.serialization.ODataBinderImpl; | ||
import org.apache.olingo.commons.api.data.Entity; | ||
import org.apache.olingo.commons.api.format.ContentType; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class JsonDeserializerTest { | ||
|
||
|
||
/** | ||
* Without the attached fix this test with the corresponding resource json will throw a {@link java.lang.IllegalArgumentException} | ||
* with the message: 'Cannot build a primitive value for Stream' | ||
* | ||
* this is because the <streamproptitle>@odata.type key is incorrectly filtered by the previous implementation | ||
*/ | ||
@Test | ||
public void testDeserializationStreamProperties() throws ODataDeserializerException { | ||
try (InputStream inputStream = getClass().getResourceAsStream("Employee.json")) { | ||
ClientODataDeserializerImpl clientODataDeserializer = | ||
new ClientODataDeserializerImpl(false, ContentType.JSON_FULL_METADATA); | ||
ResWrap<Entity> entity = clientODataDeserializer.toEntity(inputStream); | ||
ODataBinderImpl oDataBinder = new ODataBinderImpl(ODataClientFactory.getClient()); | ||
ClientEntity oDataEntity = oDataBinder.getODataEntity(entity); | ||
List<ClientLink> mediaEditLinks = oDataEntity.getMediaEditLinks(); | ||
assertEquals(2, mediaEditLinks.size()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
lib/client-core/src/test/resources/org/apache/olingo/client/core/Employee.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"@odata.context": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#Employees/$entity", | ||
"@odata.etag": "W/\"f557984846c2e312e155c9e8bede6186c4be9094b4edec2f5f32fe2a813f0cf1\"", | ||
"@odata.id": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/Employees(1)", | ||
"[email protected]": "#Int64", | ||
"Id": 1, | ||
"FirstName": "Paul", | ||
"LastName": "Mayor", | ||
"[email protected]": "#Date", | ||
"DateOfBirth": "1973-08-17", | ||
"[email protected]": "#Stream", | ||
"[email protected]": "W/\"32d1efc04f8aa14e828fa67d5161fa3664366e089b187402732a7c054ea2bc26\"", | ||
"[email protected]": "image/jpeg", | ||
"[email protected]": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/Employees(1)/Picture", | ||
"[email protected]": "#Stream", | ||
"[email protected]": "W/\"7234c31b74af36899934883c9ff09ab0c70f8d0efdab9ac1a90010074f812931\"", | ||
"[email protected]": "image/jpeg", | ||
"[email protected]": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/Employees(1)/Thumbnail" | ||
} |