Skip to content

add support for parsing JSON as AST to jsoniter codec #21

@rolang

Description

@rolang

Generated schema example

package com.anymindgroup.gcp.aiplatform.v1.schemas

import com.github.plokhotnyuk.jsoniter_scala.core.*
import com.github.plokhotnyuk.jsoniter_scala.macros.*

case class GoogleCloudAiplatformV1FunctionCall(
  // Optional
  // The name of the function to call
  // Matches [FunctionDeclaration.name].
  name: Option[String] = None,
  // Optional
  // The function parameters and values in JSON object format
  // See [FunctionDeclaration.parameters] for parameter details.
  args: Option[Map[String, Option[String]]] = None
) {
  def toJsonString: String = writeToString(this)
}

object GoogleCloudAiplatformV1FunctionCall {
  given jsonCodec: JsonValueCodec[GoogleCloudAiplatformV1FunctionCall] = 
    JsonCodecMaker.make(CodecMakerConfig.withAllowRecursiveTypes(true).withDiscriminatorFieldName(None))
}

Fails to deserialize when args contains some JSON object.
Instead of args: Option[Map[String, Option[String]]] it should be like args: Option[Map[String, Json]], but a Json type is not available in jsoniter.

Example workaround of adding AST support: Scala 3 AST

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions