Skip to content

Commit 3662884

Browse files
committed
Minor changes
Signed-off-by: Gopal S Akshintala <[email protected]>
1 parent 7562e56 commit 3662884

File tree

8 files changed

+28
-9
lines changed

8 files changed

+28
-9
lines changed

src/main/kotlin/com/salesforce/revoman/internal/json/MoshiReVoman.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package com.salesforce.revoman.internal.json
1111

1212
import com.salesforce.revoman.internal.json.adapters.BigDecimalAdapter
1313
import com.salesforce.revoman.internal.json.adapters.EpochAdapter
14+
import com.salesforce.revoman.internal.json.adapters.TypeAdapter
1415
import com.salesforce.revoman.internal.json.adapters.UUIDAdapter
1516
import com.salesforce.revoman.internal.json.factories.CaseInsensitiveEnumAdapter
1617
import com.salesforce.revoman.internal.json.factories.IgnoreUnknownFactory
@@ -54,6 +55,7 @@ internal fun buildMoshi(
5455
Moshi.Builder()
5556
.add(JsonString.Factory())
5657
.add(AdaptedBy.Factory())
58+
.add(TypeAdapter)
5759
.add(BigDecimalAdapter)
5860
.add(UUIDAdapter)
5961
.add(EpochAdapter)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* ************************************************************************************************
3+
* Copyright (c) 2023, Salesforce, Inc. All rights reserved. SPDX-License-Identifier: Apache License
4+
* Version 2.0 For full license text, see the LICENSE file in the repo root or
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
* ************************************************************************************************
7+
*/
8+
package com.salesforce.revoman.internal.json.adapters
9+
10+
import com.squareup.moshi.FromJson
11+
import com.squareup.moshi.ToJson
12+
import java.lang.reflect.Type
13+
import java.util.*
14+
15+
object TypeAdapter {
16+
@ToJson fun toJson(type: Type): String = type.toString()
17+
18+
@FromJson fun fromJson(typeStr: String): Type? = null
19+
}

src/main/kotlin/com/salesforce/revoman/internal/json/factories/CaseInsensitiveEnumAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal class CaseInsensitiveEnumAdapter<T : Enum<T>>(private val enumType: Cla
5252
moshi: Moshi
5353
): JsonAdapter<*>? {
5454
val rawType: Class<*> = Types.getRawType(type)
55-
if (!rawType.isEnum()) {
55+
if (!rawType.isEnum) {
5656
return null
5757
}
5858
return CaseInsensitiveEnumAdapter(rawType as Class<out Enum<*>>)

src/main/kotlin/com/salesforce/revoman/internal/json/factories/IgnoreUnknownFactory.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
package com.salesforce.revoman.internal.json.factories
99

1010
import com.squareup.moshi.JsonAdapter
11+
import com.squareup.moshi.JsonAdapter.Factory
1112
import com.squareup.moshi.JsonReader
1213
import com.squareup.moshi.JsonWriter
1314
import com.squareup.moshi.Moshi
1415
import com.squareup.moshi.Types
1516
import java.lang.reflect.Type
1617

17-
internal class IgnoreUnknownFactory(private val typesToIgnore: Set<Class<out Any>>) :
18-
JsonAdapter.Factory {
19-
override fun create(type: Type, annotations: Set<Annotation?>, moshi: Moshi): JsonAdapter<*> {
18+
internal class IgnoreUnknownFactory(private val typesToIgnore: Set<Class<out Any>>) : Factory {
19+
override fun create(type: Type, annotations: Set<Annotation?>, moshi: Moshi): JsonAdapter<*>? {
2020
val rawType: Class<*> = Types.getRawType(type)
2121
return if (typesToIgnore.contains(rawType)) {
2222
object : JsonAdapter<Type>() {
@@ -26,8 +26,6 @@ internal class IgnoreUnknownFactory(private val typesToIgnore: Set<Class<out Any
2626
// do nothing
2727
}
2828
}
29-
} else {
30-
moshi.nextAdapter<Any>(this, type, annotations)
31-
}
29+
} else null
3230
}
3331
}

src/main/kotlin/com/salesforce/revoman/output/report/TxnInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ data class TxnInfo<HttpMsgT : HttpMessage>(
2222
@JvmField val httpMsg: HttpMsgT,
2323
@JvmField val isJson: Boolean = true
2424
) {
25-
fun <T> getTypedTxnObj(): T? = txnObjType?.let { (it as Class<T>).cast(txnObj) }
25+
fun <T> getTypedTxnObj(): T? = (txnObjType as? Class<T>)?.cast(txnObj)
2626

2727
@JvmOverloads
2828
fun <T : Any> getTypedTxnObj(

src/test/kotlin/com/salesforce/revoman/internal/ExeUtilsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ExeUtilsTest {
2828
Moshi.Builder()
2929
.build()
3030
.adapter<Template>()
31-
.fromJson(bufferFileInResources("pmCollection/steps-with-folders.json"))!!
31+
.fromJson(bufferFileInResources("pm-templates/steps-with-folders.json"))!!
3232
.item
3333
)
3434
.map { it }

0 commit comments

Comments
 (0)