Skip to content

Commit 85f7fdb

Browse files
authored
Merge pull request #85 from galrito/bugfix/#5418
Fix data loss with null being returned on int numbers
2 parents a60319f + ab774ac commit 85f7fdb

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313

14+
## [1.3.1]
15+
16+
### Added
17+
18+
### Changed
19+
- fix(serialization): Float serialization also accepts integer values. [#85](https://github.com/microsoft/kiota-serialization-json-php/pull/85)
20+
1421
## [1.3.0]
1522

1623
### Added

src/JsonParseNode.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ public function getIntegerValue(): ?int {
7474
* @inheritDoc
7575
*/
7676
public function getFloatValue(): ?float {
77-
return is_float($this->jsonNode) ? $this->jsonNode : null;
77+
if (is_float($this->jsonNode)) {
78+
return $this->jsonNode;
79+
}
80+
if (is_int($this->jsonNode)) {
81+
return floatval($this->jsonNode);
82+
}
83+
return null;
7884
}
7985

8086
/**

tests/JsonParseNodeTest.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,18 @@ public function testGetObjectValue(): void {
6262
$this->assertEquals(123.122, $expected->getHeight());
6363
}
6464

65-
public function testGetFloatValue(): void {
65+
public function testGetFloatValueWithFloat(): void {
6666
$this->parseNode = new JsonParseNode(1243.12);
6767
$expected = $this->parseNode->getFloatValue();
6868
$this->assertEquals(1243.12, $expected);
6969
}
7070

71+
public function testGetFloatValueWithInt(): void {
72+
$this->parseNode = new JsonParseNode(1243);
73+
$expected = $this->parseNode->getFloatValue();
74+
$this->assertEquals(1243.00, $expected);
75+
}
76+
7177
/**
7278
* @throws Exception
7379
*/

0 commit comments

Comments
 (0)