Skip to content

Commit

Permalink
Fixing default parser selection
Browse files Browse the repository at this point in the history
  • Loading branch information
cworsnop-figure committed May 24, 2022
1 parent 75b5ec2 commit fe31469
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ subprojects {
}

repositories {
mavenLocal()
mavenCentral()
}

Expand Down Expand Up @@ -123,7 +122,6 @@ allprojects {
version = semVersion

repositories {
mavenLocal()
mavenCentral()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import com.google.protobuf.Message

interface InputParser {
val type: Class<*>
val default: Boolean
fun parse(input: Any, type: Class<*>, includeTypes: List<String> = emptyList()): Message
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ContractParserService(
private val parsers: List<InputParser>
) : ContractParser {
override fun parseInput(input: Any, type: Class<*>): Message =
parsers.firstOrNull { type.kotlin.isSubclassOf(it.type.kotlin) }?.parse(input, type)
parsers.firstOrNull { type.kotlin.isSubclassOf(it.type.kotlin) && it.default }?.parse(input, type)
?: throw IllegalStateException("Failed to find parser for contract input.")

override fun getParser(name: String): InputParser? =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import io.provenance.onboarding.util.toPrettyJson
import org.springframework.stereotype.Component

@Component
class JsonMessageParser : InputParser {
class JsonMessageParser(
override val default: Boolean = false
) : InputParser {
override val type: Class<*> = Message::class.java

override fun parse(input: Any, type: Class<*>, includeTypes: List<String>): Message {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import io.provenance.onboarding.util.toPrettyJson
import org.springframework.stereotype.Component

@Component
class MessageParser : InputParser {
class MessageParser(
override val default: Boolean = true
) : InputParser {
override val type: Class<*> = Message::class.java

override fun parse(input: Any, type: Class<*>, includeTypes: List<String>): Message = ObjectMapper()
Expand Down

0 comments on commit fe31469

Please sign in to comment.