Record Class JsonEntity<T>

java.lang.Object
java.lang.Record
net.tangly.gleam.model.JsonEntity<T>
Type Parameters:
T - type of Java entity to map with a JSON representation
Record Components:
properties - the fields of the JSON entity
factory - factory to create a new Java object based on the JSON entity
imports - optional import function to translate a JSON object into a Java object
exports - optional export function to translate a Java object into a JSON representation

public record JsonEntity<T>(List<JsonField<T,?>> properties, Supplier<T> factory, BiFunction<org.json.JSONObject,Object,T> imports, BiFunction<T,Object,org.json.JSONObject> exports) extends Record
Defines a mapping between JSON entity and a Java entity. We have an isomorphic structure of two graphs, meaning Java entities can contains other entities and JSON entities can contains the associated JSON entities mapping these Java entities.
  • A regular Java class is mapped. The property declarations are used to map between Java instance and JSON object.
  • A Java class is inferred from some JSON fields and lookup in the data model. Therefore the import function is specific to the business logic of the domain entity. The export function uses the regular approach.
  • A Java record is used as Java domain model representation. Therefore the import function is record specific because no setter are available. The export function uses the regular approach.

The BiFunction lambdas for imports and exports transformations are needed when the transformation process needs the context of the owning entity to perform semantic checks or mappings. If no context is required simply use the factory method providing Function lambdas.