azure-sdk-for-java: [BUG] azure-spring-data-cosmos loses decimal trailing zeros when serializing BigDecimal

Describe the bug

When azure-spring-data-cosmos serializes an entity with a BigDecimal field trailing zeros in the decimal portion are lost thus ignoring the scale. For example, 43769.30 is serialized as 43769.3.

Exception or Stack Trace There is none.

To Reproduce Create an entity with a BigDecimal field. Set the value to 43769.30 and save it to cosmos. Look in cosmos or retrieve the entity. The value is 43769.3. The important thing is the scale. Because according to BigDecimal.equals():

“this method considers two BigDecimal objects equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method)”

Expected behavior 43769.30 is saved as 43769.30

Setup (please complete the following information):

  • OS: Linux
  • IDE: IntelliJ
  • Library/Libraries: azure-spring-data-cosmos:3.18.0
  • Java version: 11
  • Frameworks: Spring Boot

Additional context In MappingCosmosConverter:

final String valueAsString = objectMapper.writeValueAsString(sourceEntity);

valueAsString has the correct string representation, ie 43769.30

but:

cosmosObjectNode = (ObjectNode) objectMapper.readTree(valueAsString);

ends up with a child node with a value of 43769.3

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • [ x ] Bug Description Added
  • [ x ] Repro Steps Added
  • [ x ] Setup information Added

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 19 (7 by maintainers)

Commits related to this issue

Most upvoted comments

That’s fine. My point is that because BigDecimal is a standard Java class, I shouldn’t have to have my own custom serializer/deserializer to save it and retrieve it from Cosmos DB. It should be handled correctly by azure-spring-data-cosmos if that means it’s converted to a string before saving to the db.

3.42 did not fix this.