Moves type to the when clause

This commit is contained in:
Vitor Pamplona
2025-12-22 12:25:07 -05:00
parent 23a7e3b535
commit 59413f3051
2 changed files with 4 additions and 6 deletions
@@ -31,15 +31,14 @@ class MessageDeserializer : StdDeserializer<Message>(Message::class.java) {
override fun deserialize( override fun deserialize(
jp: JsonParser, jp: JsonParser,
ctxt: DeserializationContext, ctxt: DeserializationContext,
): Message? { ): Message {
// Expect to start with a JSON array token // Expect to start with a JSON array token
if (jp.currentToken != JsonToken.START_ARRAY) { if (jp.currentToken != JsonToken.START_ARRAY) {
ctxt.reportWrongTokenException(this, JsonToken.START_ARRAY, "Expected START_ARRAY token") ctxt.reportWrongTokenException(this, JsonToken.START_ARRAY, "Expected START_ARRAY token")
} }
val type = jp.nextTextValue()
val message = val message =
when (type) { when (val type = jp.nextTextValue()) {
EventMessage.LABEL -> { EventMessage.LABEL -> {
val subId = jp.nextTextValue() val subId = jp.nextTextValue()
jp.nextToken() jp.nextToken()
@@ -35,15 +35,14 @@ class CommandDeserializer : StdDeserializer<Command>(Command::class.java) {
override fun deserialize( override fun deserialize(
jp: JsonParser, jp: JsonParser,
ctxt: DeserializationContext, ctxt: DeserializationContext,
): Command? { ): Command {
// Expect to start with a JSON array token // Expect to start with a JSON array token
if (jp.currentToken != JsonToken.START_ARRAY) { if (jp.currentToken != JsonToken.START_ARRAY) {
ctxt.reportWrongTokenException(this, JsonToken.START_ARRAY, "Expected START_ARRAY token") ctxt.reportWrongTokenException(this, JsonToken.START_ARRAY, "Expected START_ARRAY token")
} }
val type = jp.nextTextValue()
val message = val message =
when (type) { when (val type = jp.nextTextValue()) {
ReqCmd.LABEL -> { ReqCmd.LABEL -> {
val subId = jp.nextTextValue() val subId = jp.nextTextValue()
val filters = mutableListOf<Filter>() val filters = mutableListOf<Filter>()