-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from raynigon/bugfix/72/quantity-reader
Fix Quantity Reader/Writer Bug
- Loading branch information
Showing
8 changed files
with
126 additions
and
7 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
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
16 changes: 16 additions & 0 deletions
16
jackson-starter/src/test/groovy/com/raynigon/unit_api/jackson/helpers/CelsiusReader.groovy
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,16 @@ | ||
package com.raynigon.unit_api.jackson.helpers | ||
|
||
import com.raynigon.unit_api.core.io.QuantityReader | ||
|
||
import javax.measure.Quantity | ||
|
||
import static com.raynigon.unit_api.core.units.si.SISystemUnitsConstants.Celsius | ||
|
||
class CelsiusReader implements QuantityReader { | ||
|
||
@Override | ||
Quantity<?> read(String input) { | ||
if (!input.endsWith("°C")) return null | ||
return Celsius(Double.parseDouble(input.replace("°C", "").trim())) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
jackson-starter/src/test/groovy/com/raynigon/unit_api/jackson/helpers/PercentWriter.groovy
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,13 @@ | ||
package com.raynigon.unit_api.jackson.helpers | ||
|
||
import com.raynigon.unit_api.core.io.QuantityWriter | ||
import com.raynigon.unit_api.core.units.si.dimensionless.Percent | ||
|
||
import javax.measure.Quantity | ||
|
||
class PercentWriter implements QuantityWriter { | ||
@Override | ||
String write(Quantity input) { | ||
return "${input.to(new Percent()).value.doubleValue()}%" | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
jackson-starter/src/test/groovy/com/raynigon/unit_api/jackson/helpers/WeatherEntity.groovy
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,30 @@ | ||
package com.raynigon.unit_api.jackson.helpers | ||
|
||
|
||
import com.raynigon.unit_api.core.units.si.dimensionless.Percent | ||
import com.raynigon.unit_api.core.units.si.temperature.Celsius | ||
import com.raynigon.unit_api.jackson.annotation.JsonQuantityReader | ||
import com.raynigon.unit_api.jackson.annotation.JsonQuantityWriter | ||
import com.raynigon.unit_api.jackson.annotation.JsonUnit | ||
|
||
import javax.measure.Quantity | ||
import javax.measure.quantity.Dimensionless | ||
import javax.measure.quantity.Temperature | ||
|
||
class WeatherEntity { | ||
|
||
public WeatherEntity() {} | ||
|
||
public WeatherEntity(Quantity<Temperature> temperature, Quantity<Dimensionless> humidity) { | ||
this.temperature = temperature | ||
this.humidity = humidity | ||
} | ||
|
||
@JsonUnit(unit = Celsius) | ||
@JsonQuantityReader(CelsiusReader.class) | ||
public Quantity<Temperature> temperature | ||
|
||
@JsonUnit(unit = Percent) | ||
@JsonQuantityWriter(PercentWriter.class) | ||
public Quantity<Dimensionless> humidity | ||
} |