question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Core: TableConverter extracts child object values but not headers

See original GitHub issue

Hi! I’d like to report a bug I encountered while trying out Cucumber on my freshly-converted Kotlin Android application. I’m not entirely sure if this is a bug with Cucumber or Kotlin, so I’ll let you judge.

Steps to reproduce

  • Given TimeoLine.kt
data class TimeoLine (val id: String, val name: String, val direction: TimeoDirection, val networkCode: Int = 147, val color: String = "#34495E") {
    override fun toString(): String = name
}
  • Given TimeoDirection.kt
data class TimeoDirection (var id: String, var name: String) {
    override fun toString(): String = "$id - $name"
}

nb: As you can see, TimeoLine contains a TimeoDirection as a property named direction

  • Call DataTable.create() on a List<TimeoLine>

Expected behavior

The function returns a table that looks like this:

id name direction networkCode color
TRAM Tram A - Ifs Grace de Dieu 147 #ff3300

Observed behavior

cucumber.runtime.CucumberException: Table is unbalanced: expected 5 column(s) but found 6.
    at cucumber.api.DataTable.<init>(DataTable.java:63)
    at cucumber.runtime.table.TableConverter.createDataTable(TableConverter.java:272)
    at cucumber.runtime.table.TableConverter.toTable(TableConverter.java:258)
    at cucumber.api.DataTable.create(DataTable.java:45)
    at cucumber.api.DataTable.create(DataTable.java:31)
    at fr.outadev.android.transport.timeo.ParseStepDefinitions.iGetTheFollowingLines(ParseStepDefinitions.kt:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at cucumber.runtime.Utils$1.call(Utils.java:37)
    at cucumber.runtime.Timeout.timeout(Timeout.java:13)
    at cucumber.runtime.Utils.invoke(Utils.java:31)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
    at cucumber.runtime.Runtime.runStep(Runtime.java:299)
    [...]

By playing a bit with the DataTable conversion, you’ll see ComplexTypeWriter extracts all the values in the object, including the members of TimeoDirection; but it only extracts the headers for the properties of the parent object (TimeoLine). It also causes some not-failing-but-extremely-confusing-behavior in diffs.

  • Runtime: java-8-openjdk
  • Lib version: info.cukes:cucumber-java:1.2.4

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mpkorstanjecommented, Jun 17, 2017

As it turns out I was mistaken. To achieve the desired result you have to add a converter that tells Cucumber how to present your object in a table. This should also prevent any table imbalances.

@XStreamConverter(TimeoDirectionConvertor::class)
data class TimeoDirection (var id: String, var name: String) {
    override fun toString(): String = "$id - $name"
}

class TimeoDirectionConvertor : SingleValueConverter {

    override fun toString(p0: Any?): String = p0.toString()

    override fun fromString(p0: String?): Any = {
        val (id, name) = p0!!.split(" - ");
        TimeoDirection(id, name)
    }

    override fun canConvert(p0: Class<*>?): Boolean = TimeoDirection::class.java.isAssignableFrom(p0)
}
0reactions
lock[bot]commented, Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to show values from children object when GET an API ...
I'm using the code bellow and the response has a child object, i´d like to use those childs values on my zap but...
Read more >
Extracting just JSON data, not the headers, to a string array ...
The reason that I just want the data and not the headers is that the data could by dynamic. In one call the...
Read more >
JavaScript object model | Apigee X | Google Cloud
This table briefly describes the context object and its children, and lists the properties that are bound to each. Name, Description, Properties. context,...
Read more >
[Solved]-Entity Framework lazy loading incorrect entity-C#
When you went to reference it from another element/object, it would be silly for it to go and load it again when it...
Read more >
Object.getOwnPropertyNames() - JavaScript - MDN Web Docs
The object whose enumerable and non-enumerable properties are to be returned. Return value. An array of strings that corresponds to the properties found ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found