Welcome to js2pets, a project aimed at extending the functionality of jsonschema2pojos, which generates Java POJOs from JSON schemas. This library builds upon the capabilities of jsonschema2pojo to provide additional features and enhancements.
- Custom Rule Factory: Extend the capabilities of jsonschema2pojo by providing custom rules that suit your project needs.
- Maven and Gradle Support: Easily integrate js2pets with both Maven and Gradle projects, ensuring compatibility with your preferred build system.
- Flexible Integration: Easily integrate with the jsonschema2pojo Maven plugin by adding js2pets as a dependency.
To use js2pets in your project, follow these steps:
- Java 8 or higher
- Maven or Gradle
Add js2pets as a dependency in the jsonschema2pojo plugin configuration of your Maven project:
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>${jsonschema2pojo.version}</version>
<configuration>
<includeConstructors>true</includeConstructors>
<includeNoArgsConstructor>false</includeNoArgsConstructor>
<customRuleFactory>io.github.lengors.js2pets.factories.EnhancedRuleFactory</customRuleFactory>
</configuration>
<executions>
<execution>
<id>generate-pojos</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>io.github.lengors</groupId>
<artifactId>js2pets</artifactId>
<version>${js2pets.version}</version>
</dependency>
</dependencies>
</plugin>
To use js2pets with Gradle, configure your build.gradle.kts
as follows:
plugins {
id("org.jsonschema2pojo") version jsonschema2pojoVersion
}
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath("io.github.lengors:js2pets:$js2petsVersion")
}
}
jsonSchema2Pojo {
setCustomRuleFactory(EnhancedRuleFactory.IncludeNoArgsConstructor::class.java)
includeConstructors = true
}
Once configured, the js2pets custom rules will automatically apply when generating Java classes from your JSON schemas. Customize your JSON schema as needed, and the generated Java classes will reflect the custom rules defined in js2pets.
Given the following JSON schema:
{
"type": "object",
"properties": {
"petName": {
"type": "string"
},
"age": {
"type": "integer"
}
}
}
The jsonschema2pojo plugin, enhanced with js2pets, will generate a Java class that includes the constructors but is able to leave out the no-args constructor.
For detailed guides and additional information, please refer to our GitHub Wiki.
If you wish to check the detailed API documentation, visit the Javadoc page.
Contributions are welcome! Please refer to our Contribution Guidelines for more information on how to get involved.
This project is licensed under The Unlicense, which places it in the public domain.