Skip to content

Commit c09096a

Browse files
Merge pull request #11 from icerockdev/serialization_fix
Fixed serialization problem for responses
2 parents 7a5d142 + 6a37b30 commit c09096a

File tree

11 files changed

+23
-33
lines changed

11 files changed

+23
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repositories {
1212
}
1313

1414
// Append dependency
15-
implementation("com.icerockdev:web-utils:0.1.4")
15+
implementation("com.icerockdev:web-utils:0.2.0")
1616
````
1717

1818
## Library usage

sample/src/main/kotlin/com/icerockdev/sample/server.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ fun Application.main() {
9292

9393
class TestRequest(val email: String, @JsonSecret val password: String) : Request()
9494
class TestResponse2(status: Int, val email: String, @JsonSecret val password: String) :
95-
AbstractResponse(status, isSuccess = true) {
95+
AbstractResponse(status, success = true) {
9696
}
9797

9898
class TestResponse(status: Int, message: String) :
99-
AbstractResponse(status, message, isSuccess = true) {
99+
AbstractResponse(status, message, success = true) {
100100
@JsonSecret
101101
val data = message
102102
}

web-utils/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ apply(plugin = "java")
1313
apply(plugin = "kotlin")
1414

1515
group = "com.icerockdev"
16-
version = "0.1.5"
16+
version = "0.2.0"
1717

1818
val sourcesJar by tasks.registering(Jar::class) {
1919
classifier = "sources"

web-utils/src/main/kotlin/com/icerockdev/api/AbstractResponse.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44

55
package com.icerockdev.api
66

7-
import com.fasterxml.jackson.annotation.JsonProperty
87
import com.icerockdev.webserver.tools.DateTimeUtil
98

109
abstract class AbstractResponse(
1110
var status: Int = 0,
1211
var message: String = "",
1312
var timestamp: Long = DateTimeUtil.getTimestamp(),
14-
@JsonProperty("success")
15-
var isSuccess: Boolean = false
13+
var success: Boolean = false
1614
) {
1715
}

web-utils/src/main/kotlin/com/icerockdev/api/ErrorResponse.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class ErrorResponse() : ResponseList() {
1919

2020
private fun setValidationParams(list: List<ErrorDetail>) {
2121
this.status = 422
22-
this.isSuccess = false
22+
this.success = false
2323
this.message = "Validation Error"
24-
this.dataList = list
24+
this.data = list
2525
}
2626

2727
constructor(errorList: List<ErrorDetail>) : this() {

web-utils/src/main/kotlin/com/icerockdev/api/Response.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
package com.icerockdev.api
66

7-
import com.fasterxml.jackson.annotation.JsonProperty
87
import com.icerockdev.webserver.tools.DateTimeUtil
98

109
open class Response(
11-
@JsonProperty("data")
1210
open var data: Any? = null,
1311
status: Int = 200,
1412
message: String = "",

web-utils/src/main/kotlin/com/icerockdev/api/ResponseList.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55
package com.icerockdev.api
66

7-
import com.fasterxml.jackson.annotation.JsonProperty
87
import com.icerockdev.webserver.tools.DateTimeUtil
98

109
open class ResponseList(
11-
@JsonProperty("data")
12-
open var dataList: List<Any> = listOf(),
10+
open var data: List<Any> = listOf(),
1311
status: Int = 200,
1412
message: String = "",
1513
timestamp: Long = DateTimeUtil.getTimestamp(),

web-utils/src/main/kotlin/com/icerockdev/exception/ExtUserException.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@
44

55
package com.icerockdev.exception
66

7-
import com.fasterxml.jackson.annotation.JsonProperty
87
import com.icerockdev.api.ErrorResponse
98

109
abstract class ExtUserException(status: Int, message: String) :
1110
UserException(status, message) {
12-
@JsonProperty("data")
13-
open var dataList: List<ErrorDetail> = mutableListOf()
11+
open var data: List<ErrorDetail> = mutableListOf()
1412

1513
override fun getErrorResponse(): ErrorResponse {
1614
return ErrorResponse().also {
1715
it.status = this.status
1816
it.message = this.message.toString()
19-
it.isSuccess = false
20-
it.dataList = dataList
17+
it.success = false
18+
it.data = data
2119
}
2220
}
2321

2422
protected fun setErrors(list: List<ErrorDetail>) {
25-
this.dataList = list
23+
this.data = list
2624
}
2725
}

web-utils/src/main/kotlin/com/icerockdev/exception/UserException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ abstract class UserException(
1515
return ErrorResponse().also {
1616
it.status = this.status
1717
it.message = this.message ?: ""
18-
it.isSuccess = false
18+
it.success = false
1919
}
2020
}
2121
}

web-utils/src/main/kotlin/com/icerockdev/webserver/configuration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fun getStatusConfiguration(): StatusPages.Configuration.() -> Unit {
4545
val error = ErrorResponse().also {
4646
it.status = status.value
4747
it.message = "Unauthorized"
48-
it.isSuccess = false
48+
it.success = false
4949
}
5050
call.respond(
5151
status,

0 commit comments

Comments
 (0)