Skip to content

[Bug]: Api convertJsonToRecord() Fails with Readonly Record Fields #43969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
DimuthuMadushan opened this issue Apr 4, 2025 · 0 comments · May be fixed by #43982
Open

[Bug]: Api convertJsonToRecord() Fails with Readonly Record Fields #43969

DimuthuMadushan opened this issue Apr 4, 2025 · 0 comments · May be fixed by #43982
Assignees
Labels
Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug

Comments

@DimuthuMadushan
Copy link
Contributor

Description

The GraphQL native uses the convertJsonToRecord() API from io.ballerina.runtime.api.utils.JsonUtils to convert a JSON value into a record. However, it throws the following exception when processing a JSON value containing readonly fields:

error("{ballerina/lang.map}InvalidUpdate", message="Invalid update of record field: modification not allowed on readonly value")

Record Type:

public type TvSeries record {
    string name;
    Episode[] & readonly episodes?;
};

public type Episode record {
    string title;
};

Value:

{
  "tvSeries": [
    {
      "name": "Sherlock Holmes",
      "episodes": [
        {
          "title": "ep1"
        }
      ]
    }
  ]
}

Steps to Reproduce

Run following GraphQL service with given query and variables.

import ballerina/graphql;

public type TvSeries record {
    string name;
    Episode[] & readonly episodes?;
};

public type Episode record {
    string title;
};

public type Movie record {
    string movieName;
    string director?;
};

@graphql:ServiceConfig {
    graphiql: {
        enabled: true
    }
}
service /list_inputs on new graphql:Listener(9090) {

    resource function get getSuggestions(TvSeries[] tvSeries) returns Movie[] {
        Movie[] results = [m1, m2];
        foreach TvSeries item in tvSeries {
            if item.name == "Breaking Bad" {
                results = [m1, m2];
            } else {
                results = [m1, m2];
            }
        }
        return results;
    }
}

Movie m1 = {
    movieName: "Harry Potter and the Sorcerer's Stone",
    director: "Chris Columbus"
};

Movie m2 = {
    movieName: "Sherlock Holmes",
    director: "Dexter Fletcher"
};

Query:

query ($tvSeries: [TvSeries!]!){
  getSuggestions(tvSeries: $tvSeries) {
    movieName
    director
  }
}

variables:

{
  "tvSeries":[
    {
      "name": "Sherlock Holmes",
      "episodes": [
        {
          "title": "ep1"
        }
      ]
    }
  ]
}

Affected Version(s)

u12

OS, DB, other environment details and versions

No response

Related area

-> Runtime

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug
Projects
Status: PR Sent
Development

Successfully merging a pull request may close this issue.

3 participants