Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Added util function jsonTypeRef for simplification of TypeR… #741

Merged
merged 3 commits into from Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -49,7 +49,7 @@ data class GraphQLResponse(val json: String, val headers: Map<String, List<Strin
*/

val data: Map<String, Any> = parsed.read("data") ?: emptyMap()
val errors: List<GraphQLError> = parsed.read("errors", object : TypeRef<List<GraphQLError>>() {}) ?: emptyList()
val errors: List<GraphQLError> = parsed.read("errors", jsonTypeRef<List<GraphQLError>>()) ?: emptyList()

constructor(json: String) : this(json, emptyMap())

Expand Down Expand Up @@ -136,3 +136,5 @@ data class GraphQLResponse(val json: String, val headers: Map<String, List<Strin

@JsonIgnoreProperties(ignoreUnknown = true)
data class RequestDetails(val requestId: String?, val edgarLink: String?)

inline fun <reified T> jsonTypeRef(): TypeRef<T> = object : TypeRef<T>() {}
Expand Up @@ -16,8 +16,8 @@

package com.netflix.graphql.dgs.client

import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.netflix.graphql.types.subscription.*
import graphql.GraphQLException
import org.springframework.web.reactive.socket.WebSocketMessage
Expand Down Expand Up @@ -263,7 +263,7 @@ class OperationMessageWebSocketClient(

private fun decodeMessage(message: WebSocketMessage): OperationMessage {
val messageText = message.payloadAsText
val type = object : TypeReference<OperationMessage>() {}
val type = jacksonTypeRef<OperationMessage>()

return MAPPER.readValue(messageText, type)
}
Expand Down
Expand Up @@ -16,7 +16,6 @@

package com.netflix.graphql.dgs.client

import com.jayway.jsonpath.TypeRef
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.springframework.http.HttpEntity
Expand Down Expand Up @@ -184,9 +183,9 @@ class GraphQLResponseTest {
emptyMap(), requestExecutor
)

val listOfSubmittedBy: List<String> = graphQLResponse.extractValueAsObject(
val listOfSubmittedBy = graphQLResponse.extractValueAsObject(
"submitReview.edges[*].node.submittedBy",
object : TypeRef<List<String>>() {}
jsonTypeRef<List<String>>()
)
assertThat(listOfSubmittedBy).isInstanceOf(ArrayList::class.java)
assertThat(listOfSubmittedBy.size).isEqualTo(2)
Expand Down
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.netflix.graphql.types.subscription.*
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -76,7 +76,7 @@ class OperationMessageTest {
}

private fun deserialize(message: String) =
MAPPER.readValue(message, object : TypeReference<OperationMessage>() {})
MAPPER.readValue(message, jacksonTypeRef<OperationMessage>())

companion object {
val MAPPER = jacksonObjectMapper()
Expand Down