Coder Social home page Coder Social logo

sanmak / json-to-kotlin-class Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 62 KB

JSON to Kotlin Class

Home Page: https://boxpiper.com/

License: MIT License

JavaScript 100.00%
data-class javascript javascript-library json json-2-kotlin json-conversion json-converter json-convertor json-to-kotlin json-transform json-transformation json2kotlin jsontokotlin kotlin kotlin-js mocha mocha-chai mocha-tests transform transformer

json-to-kotlin-class's Issues

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

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.