Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Niels-Erik
Copy link
Contributor

@Niels-Erik Niels-Erik commented Nov 12, 2024

added findSubType that takes a String and a Value, and finds the Type which also corresponds to the Value
valueToJsonString in JsUtils.java now uses the new method to find the correct subtype

This is to fix the issue reported in discord:
sundedrengen — 10/29/2024 2:02 AM
We are pretty sure we found a bug in the way Jolie generates json reponses in the following circumstance (tested on jolie commit 3b8c752):

//Doesn't happen if type is 
//type Response: B | A
type Response: A | B

type A {
    canbeanything*: undefined
    test: string
}

type B {
    test?: A
}

interface Iface {
    RequestResponse: hello(void)(Response)
}

service BugHunter {
    execution: concurrent
    inputPort ip {
        location: "socket://localhost:12345"
        protocol: http {format = "json"}
        interfaces: Iface
    }
    main {
        [hello()(Response) {
            Response << {
                test << {
                    canbeanything[0] = "This should be wrapped in an array"
                    test = ""
                    //Not wrapped because something with the same name (in this case "test") exists in both of the types (we think).
                    /*
                    curl localhost:12345/hello
                    {"test":{"test":"","canbeanything":"This should be wrapped in an array"}}
                    */
                }
            }
         }]
    }
}

Not sure if it is done in the correct way.

… which also corresponds to the Value

valueToJsonString in JsUtils.java now uses the new method to find the correct subtype
@Niels-Erik Niels-Erik changed the title added findSubType that takes a String and a Value, and finds the Type which also corresponds to the Value fix JSON converter finds correct subtype if subtypes in TypeChoice has same name Nov 12, 2024
@Niels-Erik Niels-Erik marked this pull request as ready for review November 12, 2024 19:35
@klag
Copy link
Member

klag commented Nov 13, 2024

Could you add a test http_json.ol here https://github.com/jolie/jolie/tree/master/test/extensions for checking this specific case?

@fmontesi
Copy link
Member

Agreed, a test would be nice. Otherwise the PR looks good! :)

@Niels-Erik
Copy link
Contributor Author

Thank you, I'll add a test.

@Niels-Erik
Copy link
Contributor Author

@fmontesi @klag
I've managed to create a test testing for the specific scenario.
I've tested that it fails on master and we can see from the check passing that it succeeds in this branch.

@fmontesi fmontesi merged commit 6ce3d73 into jolie:master Nov 24, 2024
6 checks passed
mwallnoefer pushed a commit that referenced this pull request Nov 25, 2024
…ct-subtype

fix JSON converter finds correct subtype if subtypes in TypeChoice has same name
@Niels-Erik Niels-Erik deleted the fix-JSON-converter-find-correct-subtype branch January 1, 2025 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants