-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OLINGO-1568] Add handling of special case precision/scale
- Loading branch information
Showing
4 changed files
with
54 additions
and
5 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
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
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
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import static org.junit.Assert.assertThat; | ||
|
||
import java.io.StringWriter; | ||
import java.math.BigDecimal; | ||
|
||
import org.apache.olingo.client.api.ODataClient; | ||
import org.apache.olingo.client.api.domain.ClientEntity; | ||
|
@@ -66,6 +67,33 @@ public void testClientEntityJSONWithNull() throws ODataSerializerException { | |
|
||
JsonSerializer jsonSerializer = new JsonSerializer(false, ContentType.JSON_FULL_METADATA); | ||
|
||
StringWriter writer = new StringWriter(); | ||
jsonSerializer.write(writer, odataClient.getBinder().getEntity(clientEntity)); | ||
assertThat(writer.toString(), is(expectedJson)); | ||
} | ||
@Test | ||
public void testClientEntityJSONWithBigDecimal() throws ODataSerializerException { | ||
String expectedJson = "{\"@odata.type\":\"#test.testClientEntity\"," | ||
+ "\"[email protected]\":\"Decimal\"," | ||
+ "\"testLeadingZerosDecimal\":0.01," | ||
+ "\"[email protected]\":\"Decimal\"," | ||
+ "\"testArbitraryPrecisionDecimal\":0.01000000000000000020816681711721685132943093776702880859375}"; | ||
|
||
ODataClient odataClient = ODataClientFactory.getClient(); | ||
ClientObjectFactory objFactory = odataClient.getObjectFactory(); | ||
ClientEntity clientEntity = objFactory.newEntity(new FullQualifiedName("test", "testClientEntity")); | ||
|
||
clientEntity.getProperties().add( | ||
objFactory.newPrimitiveProperty( | ||
"testLeadingZerosDecimal", | ||
objFactory.newPrimitiveValueBuilder().buildDecimal(new BigDecimal("0.01")))); | ||
clientEntity.getProperties().add( | ||
objFactory.newPrimitiveProperty( | ||
"testArbitraryPrecisionDecimal", | ||
objFactory.newPrimitiveValueBuilder().buildDecimal(new BigDecimal(0.01)))); | ||
|
||
JsonSerializer jsonSerializer = new JsonSerializer(false, ContentType.JSON_FULL_METADATA); | ||
|
||
StringWriter writer = new StringWriter(); | ||
jsonSerializer.write(writer, odataClient.getBinder().getEntity(clientEntity)); | ||
assertThat(writer.toString(), is(expectedJson)); | ||
|