@@ -46,40 +46,54 @@ abstract class Router(val httpClient: HttpClient) {
46
46
}
47
47
}
48
48
49
- protected suspend inline fun <reified T > fetchJsonApiResource (endpoint : String , queryParameters : Map <String , String > = emptyMap()): T {
49
+ protected suspend inline fun <reified T > fetchJsonApiResource (
50
+ endpoint : String ,
51
+ queryParameters : Map <String , String > = emptyMap(),
52
+ vararg includedClasses : Class <* >
53
+ ): T {
50
54
return try {
51
55
val rawResponse = performGet(endpoint, queryParameters)
52
- val resourceConverter = ResourceConverter (getObjectMapper(), T ::class .java).apply {
56
+
57
+ val resourceConverter = ResourceConverter (getObjectMapper(), T ::class .java, * includedClasses).apply {
53
58
enableSerializationOption(SerializationFeature .INCLUDE_RELATIONSHIP_ATTRIBUTES )
54
59
}
55
- val jsonApiResponse = resourceConverter.readDocument<T >(rawResponse.body<ByteArray >(), T ::class .java)
60
+
61
+ val jsonApiResponse = resourceConverter.readDocument<T >(
62
+ rawResponse.body<ByteArray >(), T ::class .java
63
+ )
56
64
57
65
jsonApiResponse.get() ? : throw ApiException (" Failed to parse response for $endpoint " , Exception ())
58
66
} catch (e: ClientRequestException ) {
59
67
if (e.response.status == HttpStatusCode .Unauthorized ) {
60
- throw UnauthorizedException (" Unauthorised action: $endpoint " , e.response, e)
68
+ throw UnauthorizedException (" Unauthorized action: $endpoint " , e.response, e)
61
69
}
62
-
63
70
throw ApiClientException (" Request failed: $endpoint " , e.response, e)
64
71
} catch (e: Exception ) {
65
72
throw ApiException (" Request failed: $endpoint " , e)
66
73
}
67
74
}
68
75
69
- protected suspend inline fun <reified T > fetchJsonApiResources (endpoint : String , queryParameters : Map <String , String > = emptyMap()): List <T > {
76
+ protected suspend inline fun <reified T > fetchJsonApiResources (
77
+ endpoint : String ,
78
+ queryParameters : Map <String , String > = emptyMap(),
79
+ vararg includedClasses : Class <* >
80
+ ): List <T > {
70
81
return try {
71
82
val rawResponse = performGet(endpoint, queryParameters)
72
- val resourceConverter = ResourceConverter (getObjectMapper(), T ::class .java).apply {
83
+
84
+ val resourceConverter = ResourceConverter (getObjectMapper(), T ::class .java, * includedClasses).apply {
73
85
enableSerializationOption(SerializationFeature .INCLUDE_RELATIONSHIP_ATTRIBUTES )
74
86
}
75
- val jsonApiResponse = resourceConverter.readDocumentCollection<T >(rawResponse.body<ByteArray >(), T ::class .java)
87
+
88
+ val jsonApiResponse = resourceConverter.readDocumentCollection<T >(
89
+ rawResponse.body<ByteArray >(), T ::class .java
90
+ )
76
91
77
92
jsonApiResponse.get() ? : throw ApiException (" Failed to parse response for $endpoint " , Exception ())
78
93
} catch (e: ClientRequestException ) {
79
94
if (e.response.status == HttpStatusCode .Unauthorized ) {
80
- throw UnauthorizedException (" Unauthorised action: $endpoint " , e.response, e)
95
+ throw UnauthorizedException (" Unauthorized action: $endpoint " , e.response, e)
81
96
}
82
-
83
97
throw ApiClientException (" Request failed: $endpoint " , e.response, e)
84
98
} catch (e: Exception ) {
85
99
throw ApiException (" Request failed: $endpoint " , e)
0 commit comments