Java REST Sample Code
Use the following example classes to deserialize the JSON returned by the REST api.
Â
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.doforms.rest</groupId>
<artifactId>client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>doforms_rest_client</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.29</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.29</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.29</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.29</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.9</version>
</dependency>
</dependencies>
</project>
Â
package com.doforms.rest.client;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
@Provider
public class JacksonConfig implements ContextResolver<ObjectMapper> {
private final ObjectMapper objectMapper;
public JacksonConfig() {
objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setSerializationInclusion(Include.NON_NULL);
}
public ObjectMapper getContext(Class<?> aClass) {
return objectMapper;
}
}
Â
package com.doforms.rest.client;
import java.time.OffsetDateTime;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class ClientObjects {
public static class Blob {
public String key;
public String id;
public String type;
}
public static class Column {
public String name;
public String caption;
}
public static class Customer {
public String key;
public String code;
public User administrator;
public Boolean branded;
public Integer credits;
public Integer licenses;
public String name;
public Plan plan;
public String status;
}
public static class Choice {
public String text;
public Label label;
}
public static class Device {
public String key;
public String name;
public String carrier;
public OffsetDateTime createTime;
public OffsetDateTime formTime;
public String model;
public String number;
public String os;
public String teamKey;
public OffsetDateTime updateTime;
public String version;
}
public static class Email {
public String[] addresses;
public String message;
}
public static class ErrorResult {
public String code;
public String request;
public String exception;
public String message;
}
public static class Fax {
public String[] addresses;
public String message;
}
public static class Field {
public String name;
public DataType data;
public ControlType type;
// Begin data fields
public Blob blob;
public String comment;
public OffsetDateTime date; // Ignore the time value which will always be 00:00:00Z
public OffsetDateTime datetime;
public Email email;
public Fax fax;
public Long integer;
public Location location;
public Double number;
public String[] strings;
public String text;
public OffsetDateTime time; // Ignore date value which will always be Jan 1 1970
public String value;
// End data fields
public Options options;
public List<Choice> choices;
public List<Field> fields;
public List<Row> rows;
}
public static class Form {
public String key;
public String id;
public String name;
public String displayName;
public OffsetDateTime createTime;
public String createUser;
public OffsetDateTime updateTime;
public String updateUser;
public Double version;
public List<Field> fields;
}
public static class Label {
public String en;
}
public static class Location {
public Double latitude;
public Double longitude;
public Double altitude;
public Double accuracy;
}
public static class Lookup {
public String key;
public String name;
public String description;
public Boolean useForm;
public Boolean useFilter;
public String formKey;
public String projectKey;
public Boolean update;
public Boolean encrypt;
public Long version;
public OffsetDateTime createTime;
public String createUser;
public OffsetDateTime updateTime;
public String updateUser;
public List<Column> columns;
}
public static class Notification {
public String key;
public String customerKey;
public String dispatchKey;
public String submissionKey;
public String webserviceId;
public String event;
public String status;
public String dispatchStatus;
}
public static class NotificationUpdate {
public String status;
public String message;
}
public static class Options {
public Boolean comment;
public Label commentLabel;
public String format;
public Label label;
public Long level;
public String prefix;
public Long rows;
}
public static class Plan {
public String code;
public String name;
}
public static class Project {
public String key;
public String name;
}
public static class Row {
public long index;
public List<Field> fields;
}
public static class Submission {
public String key;
public String id;
public String name;
public String formName;
public String formKey;
public Double formVersion;
public String projectKey;
public Integer offset;
public String timezone;
public OffsetDateTime receiveTime;
public List<Field> fields;
}
public static class Team {
public String key;
public String name;
}
public static class TokenRequest {
public String username;
public String password;
public String account;
public String code;
public String webservice;
}
public static class TokenResult {
public String code;
public String customerCode;
public String customerKey;
public String message;
public String resellerCode;
public String resellerKey;
public String token;
public String userKey;
public String[] accounts;
}
public static class User {
public String key;
public String email;
public String firstName;
public String lastName;
public String workPhone;
}
public enum ControlType {
// @formatter:off
@JsonProperty("action") ACTION,
@JsonProperty("approval") APPROVAL,
@JsonProperty("audio") AUDIO,
@JsonProperty("autonumber") AUTONUMBER,
@JsonProperty("barcode") BARCODE,
@JsonProperty("bluetooth_le") BLUETOOTH_LE,
@JsonProperty("button") BUTTON,
@JsonProperty("button_grid") BUTTON_GRID,
@JsonProperty("calculation") CALCULATION,
@JsonProperty("choose_one") CHOOSE_ONE,
@JsonProperty("choose_multiple") CHOOSE_MULTIPLE,
@JsonProperty("counter") COUNTER,
@JsonProperty("date_time") DATE_TIME,
@JsonProperty("email") EMAIL,
@JsonProperty("fax") FAX,
@JsonProperty("forward") FORWARD,
@JsonProperty("grid") GRID,
@JsonProperty("image") IMAGE,
@JsonProperty("instruction") INSTRUCTION,
@JsonProperty("label") LABEL,
@JsonProperty("location") LOCATION,
@JsonProperty("lookup") LOOKUP,
@JsonProperty("nfc") NFC,
@JsonProperty("numeric") NUMERIC,
@JsonProperty("page") PAGE,
@JsonProperty("payment") PAYMENT,
@JsonProperty("pod") POD,
@JsonProperty("questionnaire") QUESTIONNAIRE,
@JsonProperty("repeat") REPEAT,
@JsonProperty("retrieve") RETRIEVE,
@JsonProperty("schedule") SCHEDULE,
@JsonProperty("score") SCORE,
@JsonProperty("score_summary") SCORE_SUMMARY,
@JsonProperty("signature") SIGNATURE,
@JsonProperty("sketch") SKETCH,
@JsonProperty("table") TABLE,
@JsonProperty("text") TEXT,
@JsonProperty("trends") TRENDS,
@JsonProperty("video") VIDEO
// @formatter:on
}
public enum DataType {
// @formatter:off
@JsonProperty("blob") BLOB,
@JsonProperty("date") DATE,
@JsonProperty("datetime") DATETIME,
@JsonProperty("email") EMAIL,
@JsonProperty("fax") FAX,
@JsonProperty("fields") FIELDS,
@JsonProperty("integer") INTEGER,
@JsonProperty("location") LOCATION,
@JsonProperty("number") NUMBER,
@JsonProperty("rows") ROWS,
@JsonProperty("strings") STRINGS,
@JsonProperty("text") TEXT,
@JsonProperty("time") TIME
// @formatter:on
}
}