Skip to content

Commit

Permalink
[api]: Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Jun 30, 2024
1 parent 64c60cd commit 2e064ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions api/src/main/kotlin/nebulosa/api/atlas/Location.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package nebulosa.api.atlas

import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import nebulosa.api.beans.converters.angle.DegreesDeserializer
import nebulosa.api.beans.converters.angle.DegreesSerializer
import nebulosa.api.beans.converters.distance.MetersDeserializer
import nebulosa.api.beans.converters.distance.MetersSerializer
import nebulosa.math.Angle
import nebulosa.math.Distance
import nebulosa.nova.position.GeographicCoordinate
import nebulosa.time.TimeZonedInSeconds

data class Location(
@field:JsonDeserialize(using = DegreesDeserializer::class) override val latitude: Angle = 0.0,
@field:JsonDeserialize(using = DegreesDeserializer::class) override val longitude: Angle = 0.0,
@field:JsonDeserialize(using = MetersDeserializer::class) override val elevation: Distance = 0.0,
@field:JsonSerialize(using = DegreesSerializer::class) @field:JsonDeserialize(using = DegreesDeserializer::class) override val latitude: Angle = 0.0,
@field:JsonSerialize(using = DegreesSerializer::class) @field:JsonDeserialize(using = DegreesDeserializer::class) override val longitude: Angle = 0.0,
@field:JsonSerialize(using = MetersSerializer::class) @field:JsonDeserialize(using = MetersDeserializer::class) override val elevation: Distance = 0.0,
val offsetInMinutes: Int = 0,
) : GeographicCoordinate, TimeZonedInSeconds {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package nebulosa.api.beans.converters.distance

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.ser.std.NumberSerializers
import nebulosa.math.toMeters

class MetersSerializer : NumberSerializers.DoubleSerializer(Double::class.java) {

override fun serialize(value: Any?, gen: JsonGenerator, provider: SerializerProvider) {
super.serialize((value as? Double)?.toMeters, gen, provider)
}
}

0 comments on commit 2e064ff

Please sign in to comment.