Merge pull request #1 from sdeleuze/master

Refactor to idiomatic Spring + Kotlin code
This commit is contained in:
Reinhard Prechtl 2017-12-28 23:38:41 +01:00 committed by GitHub
commit 7ccc36c412
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 28 deletions

View file

@ -5,15 +5,9 @@ import javax.persistence.AttributeConverter
class DoubleAttributeConverter : AttributeConverter<Double, BigDecimal?> {
override fun convertToDatabaseColumn(attribute: Double?): BigDecimal? {
return if (attribute != null) {
BigDecimal(attribute)
} else {
null
}
}
override fun convertToDatabaseColumn(attribute: Double?) =
if (attribute != null) { BigDecimal(attribute) } else { null }
override fun convertToEntityAttribute(dbData: BigDecimal?): Double? {
return dbData?.toDouble()
}
override fun convertToEntityAttribute(dbData: BigDecimal?) =
dbData?.toDouble()
}

View file

@ -21,13 +21,6 @@ internal data class CityEntity(
val updatedAt: LocalDateTime = LocalDateTime.now(),
val createdAt: LocalDateTime = LocalDateTime.now()) {
// Default constructor for JPA
@Suppress("unused")
private constructor() : this(
name = "",
location = Coordinate.origin(),
updatedAt = LocalDateTime.MIN)
fun toDto(): CityDto = CityDto(
id = this.id!!,
name = this.name,

View file

@ -23,7 +23,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<kotlin.version>1.1.2-2</kotlin.version>
<kotlin.version>1.1.2-5</kotlin.version>
<mockito.version>2.8.9</mockito.version>
<assertj.version>3.8.0</assertj.version>
</properties>
@ -105,6 +105,7 @@
<configuration>
<compilerPlugins>
<plugin>spring</plugin>
<plugin>jpa</plugin>
</compilerPlugins>
<jvmTarget>1.8</jvmTarget>
</configuration>
@ -130,6 +131,11 @@
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>

View file

@ -1,8 +1,5 @@
package de.rpr.mycity
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.InjectionPoint
@ -18,13 +15,6 @@ class Application {
@Scope("prototype")
fun logger(injectionPoint: InjectionPoint): Logger = LoggerFactory.getLogger(injectionPoint.methodParameter.containingClass)
@Bean
fun objectMapper(): ObjectMapper {
val mapper = ObjectMapper().registerModule(KotlinModule())
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
return mapper
}
}
fun main(args: Array<String>) {