-
-
Notifications
You must be signed in to change notification settings - Fork 14
Quick start
Ahmad K. Bawaneh edited this page Apr 7, 2021
·
12 revisions
Setting up domino-jackson and using it in your project is a very easy process, simplified as Add dependency, Annotate the POJO, and finally use the generated mapper :
Add the following dependencies to your pom file
Latest release
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-jackson</artifactId>
<version>1.0.0-RC3</version>
</dependency>
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-jackson-processor</artifactId>
<version>1.0.0-RC3</version>
<scope>provided</scope>
</dependency>
Development snapshot
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-jackson</artifactId>
<version>HEAD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-jackson-processor</artifactId>
<version>HEAD-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
GWT 2.8.2 snapshot
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-jackson</artifactId>
<version>1.0-alpha-gwt2.8.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.dominokit.jackson</groupId>
<artifactId>domino-jackson-processor</artifactId>
<version>1.0-alpha-gwt2.8.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Notice this is still a snapshot, in order to use snapshots you need to add the snapshots repositories to your maven settings.xml or to your project pom repositories section.
<repository>
<id>sonatype-snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
<repository>
<id>vertispan-snapshots-repo</id>
<url>https://repo.vertispan.com/gwt-snapshot/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
If you want to use this library with GWT2.x you will need to add the
inherits
directive to your gwt.xml file
GWT2.9.0
<inherits name="org.dominokit.jackson.Jackson"/>
GWT2.8.2
<inherits name="org.dominokit.jacksonapt.GwtJacksonApt"/>
Annotate your pojo as a JSONMapper
import org.dominokit.jacksonapt.annotation.JSONMapper;
@JSONMapper
public class Person {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
This will generate a JSON mapper for the Person class.
public static void main(String[] args) {
Person person = new Person();
person.setFirstName("Ahmad");
person.setLastName("Bawaneh");
String personJsonString = Person_MapperImpl.INSTANCE
.write(person);
//{"firstName":"Ahmad","lastName":"Bawaneh"}
Person person2 = Person_MapperImpl.INSTANCE.read("{\"firstName\":\"Ahmad\",\"lastName\":\"Bawaneh\"}");
}