@lancercomet/suntori.generator
v1.2.0
Published
A codegen to create SunTori codes from JSON.
Downloads
9
Maintainers
Readme
SunTori codegen
A codegen to create SunTori codes from JSON.
import { generate } from '@lancercomet/suntori.generator'
const result = await generate({
jsonObject: {
name: 'John Smith',
age: 200,
address: [
{
name: 'Home',
locaiton: 'The earth'
}
]
},
rootClassName: 'User'
})
Result:
@Serializable()
class UserAddress {
@JsonProperty('name')
name: string = ''
@JsonProperty('location')
location: string = ''
}
@Serializable()
class User {
@JsonProperty('name')
name: string = ''
@JsonProperty('age')
age: number = 0
@JsonProperty({
name: 'address',
type: UserAddress
})
address: UserAddress[] = []
}
Options
jsonObject: never
The JSON payload. Should be a JavaScript Object.rootClassName: string = 'Root'
The name for generated class. And it will be used as prefix for all subclasses.useCamelCase: boolean = true
UsecamelCase
during code generation.addReadonly: boolean = true
Addreadonly
modifier to all members of a class.
About null
All null
JSON fields would be converted to the unknown
, as well as empty arrays.
await generate({
jsonObject: {
a: null,
b: []
}
})
// To
@Serializable()
class Root {
@JsonProperty('a')
a: unknown = null
@JsonProperty('b')
b: unknown[] = []
}
License
Apache-2.0