Note: This file is written in Markdown and is best viewed with a Markdown viewer (e.g., GitHub, GitLab, VS Code, or a dedicated Markdown reader). Viewing it in a plain text editor may not render the formatting as intended.
Copyright (c) 2026 Software Tree
This project demonstrates how JDX ORM can persist and retrieve JSON-based domain objects directly to and from a relational database — without requiring traditional Java POJOs with explicit getter/setter fields.
Instead of a conventional Java class, the domain model is built on top of the JDX_JSONObject class, which serves as the foundational base class for handling persistence of domain-specific JSON objects. Application code defines a minimal subclass (e.g., JSON_Employee) with just two constructors.
The ORM mapping uses VIRTUAL_ATTRIB declarations to define the persistent JSON properties and their types declaratively, allowing JDX to bridge the dynamic JSON model to a fixed relational schema.
A JSON_Employee instance can be initialized in three convenient ways:
- Using the
put(key, value)API to set attributes programmatically. - From an existing
JSONObjectinstance. - From a JSON string (e.g., received from a web service).
- Java JDK 8 or higher installed and on the system PATH.
- JDX ORM SDK installed. Set the environment variable
JX_HOMEto the SDK's top-level installation directory. - A supported JDBC-compatible database (SQLite is pre-configured; a MySQL example is also included in the
.jdxfile).
JDX_JSONExample/
├── config/
│ └── json_example.jdx # ORM mapping specification file
├── src/
│ └── com/softwaretree/jdxjsonexample/
│ ├── JSONExample.java # Main application entry point
│ └── model/
│ └── JSON_Employee.java # JSON-based Employee model class
├── bin/ # Compiled .class files (generated)
├── sources.txt # List of Java source files for compilation
├── compile.cmd # Windows: compile the Java source files
├── compile.sh # Mac/Linux: compile the Java source files
├── setEnvironment.bat # Windows: sets classpath environment variable
├── setEnvironment.sh # Mac/Linux: sets classpath environment variable
├── runJDXExample.bat # Windows: run the sample application
├── runJDXExample.sh # Mac/Linux: run the sample application
├── forward.bat # Windows: create/recreate the database schema
├── forward.sh # Mac/Linux: create/recreate the database schema
├── JDXDemo.bat # Windows: launch the JDXDemo GUI application
├── JDXDemo.sh # Mac/Linux: launch the JDXDemo GUI application
└── README.md # This file
Unlike the other JDX examples that use traditional POJOs, JSON_Employee extends JDX_JSONObject and defines only two constructors. All attribute storage and retrieval is handled internally by the JSONObject key-value store.
The persistent properties of a JSON_Employee and how they map to the database are defined entirely in the .jdx mapping file using VIRTUAL_ATTRIB:
| JSON Property | Java Type | DB Column | Notes |
|---|---|---|---|
id |
int |
id |
Primary key |
name |
String |
name |
|
exempt |
boolean |
exempt |
|
compensation |
double |
salary |
Column name remapped via SQLMAP |
DOB |
long |
DOB |
Stored as milliseconds; mapped to SQL DATE |
This file is the central piece that makes the JSON-based model work with JDX ORM. Key elements:
JDX_DATABASEandJDBC_DRIVER— database connection and driver settings. Pre-configured for SQLite; a commented-out MySQL example is also included.VIRTUAL_ATTRIB— declares each persistent JSON property and its Java type. BecauseJSONObjectstores data dynamically (not in typed Java fields), JDX needs these declarations to know which keys to persist and how to map them to SQL column types.PRIMARY_KEY id— designatesidas the primary key.SQLMAP FOR compensation COLUMN_NAME salary— maps the JSON propertycompensationto a database column namedsalary.SQLMAP FOR DOB SQLTYPE DATE— instructs JDX to use the SQLDATEtype for theDOBvalue, which is stored in theJSONObjectas along(milliseconds since epoch).
Refer to the JDX Database & JDBC Driver Specification Guide for configuring other databases.
Note: Update
JDX_DATABASEandJDBC_DRIVERto match your local database setup before running.
A minimal shell class that extends JDX_JSONObject. It defines only two constructors — a no-arg constructor and one that accepts a JSONObject — and inherits all persistence behavior from the superclass. No fields, getters, or setters are needed.
The entry point of the sample application. It initializes JDX ORM and demonstrates the following:
- Delete all existing
JSON_Employeeobjects from the database. - Insert
Mark— built using theput(key, value)API directly on aJSON_Employeeinstance. - Insert
David— built from an explicitly constructedJSONObjectinstance passed to theJSON_Employeeconstructor. - Insert
Steve— built by parsing a raw JSON string (simulating data arriving from a web service) into aJSONObject, then wrapping it inJSON_Employee. - Query all employees and print results.
- Retrieve employee
David(id=2) by object ID. - Extract the underlying
JSONObjectfrom the retrieved employee and print its string representation.
Lists all .java source files to be compiled, one per line:
./src/com/softwaretree/jdxjsonexample/model/JSON_Employee.java
./src/com/softwaretree/jdxjsonexample/JSONExample.java
This file is passed to javac using the @sources.txt argument syntax.
Compiles all Java source files listed in sources.txt and outputs .class files into the bin/ directory.
- Requires
JX_HOMEto be set to the JDX ORM SDK installation directory. - Links against
jxclasses.jar(JDX ORM library) andjson-20240303.jar(forJSONObjectsupport). compile.cmd— Windows batch script (supports JDK 8; a commented line supports JDK 9+).compile.sh— Mac/Linux shell script equivalent.
Windows:
compile.cmdMac/Linux:
chmod +x compile.sh # first time only
./compile.shSets the CLASSPATH environment variable to include the JDX ORM libraries, the org.json library, and the appropriate JDBC driver JAR. Edit this file to point to the correct JDBC driver for your database before running the application.
Note that json-20240303.jar is included here in addition to the other examples, as it is a runtime dependency for the JSON object model.
setEnvironment.bat— Windows (uses;as classpath separator).setEnvironment.sh— Mac/Linux (uses:as classpath separator; sourced viasource ./setEnvironment.sh).
Invokes the environment setup script to configure the classpath, then runs the JSONExample main class.
Windows:
runJDXExample.batMac/Linux:
chmod +x runJDXExample.sh # first time only
./runJDXExample.shCreates (or recreates) the database schema based on the ORM specification in the .jdx file, without running the application.
Windows:
forward -createMac/Linux:
chmod +x forward.sh # first time only
./forward.sh -createLaunches the JDXDemo desktop GUI application, which provides a graphical way to browse and interact with the database using the JDX ORM configuration.
Windows:
JDXDemo.batMac/Linux:
chmod +x JDXDemo.sh # first time only
./JDXDemo.sh-
Set
JX_HOMEto the root of your JDX ORM SDK installation. -
Configure the database by editing
config/json_example.jdx:- Update
JDX_DATABASEwith the correct connection URL and credentials. - Update
JDBC_DRIVERwith the appropriate JDBC driver class. - Update
setEnvironment.bat(Windows) orsetEnvironment.sh(Mac/Linux) to include the JDBC driver JAR on the classpath.
- Update
-
Compile the source files:
compile.cmd # Windows ./compile.sh # Mac/Linux
-
Run the sample application:
runJDXExample.bat # Windows ./runJDXExample.sh # Mac/Linux
The application will automatically create the database schema on first run (controlled by the
forceCreateSchemaflag inJSONExample.java).
Mac/Linux tip: Run
chmod +x *.shonce in the project directory to make all shell scripts executable.
This project can be imported directly into the Eclipse IDE as an existing Java project using File → Import → Existing Projects into Workspace.
- JDX Database & JDBC Driver Specification Guide
- JDX ORM SDK documentation (included in your SDK installation under
JX_HOME)