jsontopojo

Auto creating POJO from JSON.

License

License

Categories

Categories

JSON Data
GroupId

GroupId

io.github.akayibrahim
ArtifactId

ArtifactId

jsontopojo
Last Version

Last Version

1.6
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

jsontopojo
Auto creating POJO from JSON.
Project URL

Project URL

http://maven.apache.org
Source Code Management

Source Code Management

https://github.com/akayibrahim/jsontopojo

Download jsontopojo

How to add to project

<plugin>
    <groupId>io.github.akayibrahim</groupId>
    <artifactId>jsontopojo</artifactId>
    <version>1.6</version>
</plugin>

Dependencies

compile (7)

Group / Artifact Type Version
org.apache.maven : maven-plugin-api jar 3.6.3
org.apache.maven : maven-project jar 2.2.1
com.sun.codemodel : codemodel jar 2.6
com.google.code.gson : gson jar 2.2.4
jdom : jdom jar 1.1
org.projectlombok : lombok jar 1.18.10
com.fasterxml.jackson.core : jackson-annotations jar 2.10.1

provided (1)

Group / Artifact Type Version
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.3

test (1)

Group / Artifact Type Version
junit : junit jar 3.8.1

Project Modules

There are no modules declared in this project.

JSON TO POJO Maven Plugin

This Maven Plugin is for creating POJO's automatically from json.

Follow steps:
  1. Add below build tag to pom.xml of your project
<build>
    <plugins>
      <plugin>
        <groupId>io.github.akayibrahim</groupId>
        <artifactId>jsontopojo</artifactId>
        <version>1.5</version>
        <executions>
          <execution>
            <configuration>
              <json>
                {
                  "employee": {
                  "name":       "sonoo",
                  "salary":      56000,
                  "married":    true
                  }
                }
              </json>
              <path>io.githup.akayibrahim.testing</path> <!-- mandatory -->
              <className>EmployeeTesting</className> <!-- mandatory -->
              <lombok>true</lombok> <!-- optional -->
              <prefix>Pre</prefix> <!-- optional -->
              <postfix>Post</postfix> <!-- optional -->
              <throwForDuplicateObjectName>false</throwForDuplicateObjectName> <!-- optional - default: false
                If it is set true, the plugin will throw error for duplicate object name. You have to fix this names at json and regenerate. 
                If it is set false, the plugin will add "_$" postfix for duplicate object name and add TODO to this class for change information. -->
            </configuration>
            <goals>
              <goal>create</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  1. Run mvn clean install. Once the build is complete, navigate to the project root folder and you should see POJO's file.

Maven Repo Link => https://repo.maven.apache.org/maven2/io/github/akayibrahim/

NOTE : All data in json should not be null or empty. Tool generate TODO comment for null fields, so you can fix it. Please search TODO comment after generate POJO's.

NOTE : For using lombok, you have to add lombok dependency to your pom.xml.

    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.10</version>
    </dependency>

NOTE 2 : For using jackson, you have to add jackson dependency to your pom.xml. it is necessary for "throwForDuplicateObjectName" key.

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>2.10.1</version>
     </dependency>

Thanks to https://github.com/giordamauro/json-to-pojo/

Versions

Version
1.6
1.5
1.4
1.3
1.2
1.1
1.0