This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add jackson-core dependency and refactor JSON handling
The jackson-core dependency was added in `pom.xml` to enhance JSON handling in the application. The `DeviceMeasurement` class was refactored to handle null fields when generating JSON output. Helper methods were introduced for managing `externalDataReference`, `dateCreated`, and `location` fields. This change improves output cleanliness and standardizes data for users and systems.
- Loading branch information
1 parent
92d180b
commit 3a35e31
Showing
3 changed files
with
79 additions
and
12 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
43 changes: 43 additions & 0 deletions
43
src/test/java/de/app/fivegla/fiware/api/DeviceMeasurementValidJsonTest.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,43 @@ | ||
package de.app.fivegla.fiware.api; | ||
|
||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import de.app.fivegla.fiware.model.builder.DeviceMeasurementBuilder; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
||
class DevxiceMeasurementValidJsonTest { | ||
|
||
@Test | ||
void givenDeviceMeasurement_WhenCreatingJson_ThenTheResultShouldBeValidJson() throws Exception { | ||
var deviceMeasurementAsJson = new DeviceMeasurementBuilder() | ||
.withId(UUID.randomUUID().toString()) | ||
.withType(FiwareType.TEXT.name()) | ||
.withMeasurement("value", FiwareType.TEXT, 2.0, Instant.now(), 4.0, 8.0) | ||
.build() | ||
.asJson(); | ||
var objectMapper = new ObjectMapper(); | ||
var jsonNode = objectMapper.readTree(deviceMeasurementAsJson); | ||
Assertions.assertEquals(FiwareType.TEXT.getKey(), jsonNode.get("type").asText()); | ||
Assertions.assertEquals(2.0, jsonNode.get("value").asDouble()); | ||
} | ||
|
||
@Test | ||
void givenDeviceMeasurementWithExternalDataReference_WhenCreatingJson_ThenTheResultShouldBeValidJson() throws Exception { | ||
var deviceMeasurementAsJson = new DeviceMeasurementBuilder() | ||
.withId(UUID.randomUUID().toString()) | ||
.withType(FiwareType.TEXT.name()) | ||
.withMeasurement("value", FiwareType.TEXT, 2.0, Instant.now(), 4.0, 8.0) | ||
.withExternalDataReference("http://example.com") | ||
.build() | ||
.asJson(); | ||
var objectMapper = new ObjectMapper(); | ||
var jsonNode = objectMapper.readTree(deviceMeasurementAsJson); | ||
Assertions.assertEquals(FiwareType.TEXT.getKey(), jsonNode.get("type").asText()); | ||
Assertions.assertEquals(2.0, jsonNode.get("value").asDouble()); | ||
} | ||
|
||
} |