Skip to content

Commit

Permalink
[OLINGO-1609] Fix issue in JSON deserializer
Browse files Browse the repository at this point in the history
fix issue with multiple stream properties and metadata=full for deserialization
  • Loading branch information
Scraylex authored and mibo committed Oct 13, 2023
1 parent 6a800be commit 7a50c58
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ protected ResWrap<Entity> doDeserialize(final JsonParser parser) throws IOExcept
toRemove.add(link.getTitle() + "@" + annotation.getTerm());
}
}
if (tree.get(link.getTitle() + Constants.JSON_TYPE) != null) {
toRemove.add(link.getTitle() + Constants.JSON_TYPE);
}
}

tree.remove(toRemove);
Expand Down
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);
}
}
}
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"
}

0 comments on commit 7a50c58

Please sign in to comment.