fun parse()

in src/main/kotlin/org/opensearch/commons/notifications/action/SendNotificationRequest.kt [74:103]


        fun parse(parser: XContentParser): SendNotificationRequest {
            var eventSource: EventSource? = null
            var channelMessage: ChannelMessage? = null
            var channelIds: List<String>? = null
            var threadContext: String? = null

            XContentParserUtils.ensureExpectedToken(
                XContentParser.Token.START_OBJECT,
                parser.currentToken(),
                parser
            )
            while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
                val fieldName = parser.currentName()
                parser.nextToken()
                when (fieldName) {
                    EVENT_SOURCE_TAG -> eventSource = EventSource.parse(parser)
                    CHANNEL_MESSAGE_TAG -> channelMessage = ChannelMessage.parse(parser)
                    CHANNEL_ID_LIST_TAG -> channelIds = parser.stringList()
                    THREAD_CONTEXT_TAG -> threadContext = parser.textOrNull()
                    else -> {
                        parser.skipChildren()
                        log.info("Unexpected field: $fieldName, while parsing SendNotificationRequest")
                    }
                }
            }
            eventSource ?: throw IllegalArgumentException("$EVENT_SOURCE_TAG field absent")
            channelMessage ?: throw IllegalArgumentException("$CHANNEL_MESSAGE_TAG field absent")
            channelIds ?: throw IllegalArgumentException("$CHANNEL_ID_LIST_TAG field absent")
            return SendNotificationRequest(eventSource, channelMessage, channelIds, threadContext)
        }