Karate: long pending JS to JSON conversion issue - nested arrays become maps

Created on 25 May 2019  路  7Comments  路  Source: intuit/karate

a very annoying issue that has been around since the beginning, but fortunately only affects a relatively rare case when JSON is constructed on the JavaScript side (typically in an eval or JS function) and where there are nested arrays, they become JSON with keys like 0, 1, 2, etc. just figured out a possible fix. opening this issue to track, and this could be a breaking change for some teams

details: https://stackoverflow.com/a/54256766/143475

bug fixed

Most helpful comment

The commit 38ad211 seems to break java interop for us, but maybe we're doing something incorrectly so let me know. It goes like this:

In our karate-config.js, we add a reference to a Java type (which is actually a Kotlin object) that has a function we want to call in our scenarios, e.g. karate-config.js

function fn() {
  var config = {};
  // INSTANCE is a reference to a singleton instance of the kotlin object
  config.testDataSetup = Java.type('com.example.TestDataSetup').INSTANCE;
  return config;
}

Then in our scenario:

* def testUser = testDataSetup.createTestUserInDb()

I've built the commit preceding 38ad211 and it works fine, but when using a build of 38ad211 we get javascript evaluation failed: testDataSetup.createTestUserInDb is not a function in <eval> at line number 1

I'll have a bit of a debug with the changes in 38ad211 but also maybe you know off the bat what's wrong?

All 7 comments

pasting the effect of this fix, also linking old issue #225

image

The commit 38ad211 seems to break java interop for us, but maybe we're doing something incorrectly so let me know. It goes like this:

In our karate-config.js, we add a reference to a Java type (which is actually a Kotlin object) that has a function we want to call in our scenarios, e.g. karate-config.js

function fn() {
  var config = {};
  // INSTANCE is a reference to a singleton instance of the kotlin object
  config.testDataSetup = Java.type('com.example.TestDataSetup').INSTANCE;
  return config;
}

Then in our scenario:

* def testUser = testDataSetup.createTestUserInDb()

I've built the commit preceding 38ad211 and it works fine, but when using a build of 38ad211 we get javascript evaluation failed: testDataSetup.createTestUserInDb is not a function in <eval> at line number 1

I'll have a bit of a debug with the changes in 38ad211 but also maybe you know off the bat what's wrong?

@tellisnz-shift thanks, we need more info like return type of createTestUserInDb, but I would request to provide a working example to replicate this. can you please follow https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Return type is irrelevant. The above should be enough info I would have thought, but have also created an example here.

@tellisnz @tellisnz-shift thanks for noticing this, I have fixed this and also added a test-case. java references were indeed being "lost" until the fix. can you check if it is ok now ?

:+1: looks good.

released 0.9.3

Was this page helpful?
0 / 5 - 0 ratings