Skip to content
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

Calling the init function multiple times causes the output to be appended. #2

Open
prathmeshgodse opened this issue May 10, 2023 · 0 comments

Comments

@prathmeshgodse
Copy link

prathmeshgodse commented May 10, 2023

Using the below function in a node project.

`
const jsonToKotlin = require('json-to-kotlin-class')

export const getDataClass = (json: object): string => {
return jsonToKotlin.inti(json)
}
`

`
describe("j2k file", () => {
it("should generate data classes", () => {

const jsonData = [
  {
    "someString": "string",
    "someBoolean": false,
    "someNumber": 12312783,
    "someArrayOfNumber": [12837129381, 172312]
  },
  {
    "someObject": {
      "someNestedNumber": 812031923,
      "someNestedString": "string"
    }
  }
]

const dataClasses = jsonData.map(json => getDataClass(json))
console.log(dataClasses.toString());

})
})
`

Running the above test gives the below output.

data class JsonToKotlinMain (val someString: String, val someBoolean: Boolean, val someNumber: Int, val someArrayOfNumber: Array<Int>, ), data class JsonToKotlinMain (val someString: String, val someBoolean: Boolean, val someNumber: Int, val someArrayOfNumber: Array<Int>, ) data class JsonToKotlinBaseSomeObject (val someNestedNumber: Int, val someNestedString: String, ) data class JsonToKotlin2 (val someObject: JsonToKotlinBaseSomeObject, )

Note that the first object is repeated twice.
Is there any way to create stop this appending behavior?

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

No branches or pull requests

1 participant