Skip to main content

Java

You can export the data generated by schemas or any type of data to java format.
When exporting in this format, a zip file will be created with all the classes involved in the generation and a main file where all the data is initialized.

What can you export?

Data can only be exported in two ways:

  • A primitive javascript data type
  • An object with data
  • An array with similar objects (objects must have the same fields and the values of these fields must belong to the same data type)

Example Case

const userSchema = chaca.schema({
id: schemas.id.uuid(),
username: schemas.internet.userName(),
image: { type: schemas.image.people(), posibleNull: 50 },
posts: {
type: schemas.id.uuid(),
isArray: {
min: 1,
max: 5,
},
},
})

await userSchema.generateAndExport({
filaName: 'data',
format: 'java',
location: 'folder',
})

For example, if we have this schema, we generate 5 documents and export them in java format, we will obtain the following result.

Main.java
public class Main {
public static void main(String[] args){
List<Objectc28a2a92c669b3ddb6aa0b32> schema = LinkedList<>();
Objectc28a2a92c669b3ddb6aa0b32 schema1 = new Objectc28a2a92c669b3ddb6aa0b32("1ed700e9-2801-4031-922b-6b1e166a4e15", "Dylan.", null, java.util.Arrays.asList(new String[]{"28978d79-eaa0-4497-b96e-c9be59ca7c3b", "05b8dced-b762-4129-b965-3615501e78c9", "d598603e-92d6-4d00-8e91-3386b0243b28", "a09063c6-a019-4533-b340-7670846c83e7"}));
Objectc28a2a92c669b3ddb6aa0b32 schema2 = new Objectc28a2a92c669b3ddb6aa0b32("908d8879-2008-4351-8d69-744716854446", "Cameron.", null, java.util.Arrays.asList(new String[]{"7d31947c-678e-4b44-9d72-7e03412817de", "02088713-a50d-4d77-944c-98ecb2480855", "965bb87c-7e99-4076-915b-d8143a910107"}));
Objectc28a2a92c669b3ddb6aa0b32 schema3 = new Objectc28a2a92c669b3ddb6aa0b32("778eb54b-3402-4942-b6ec-06303de68378", "Isaiah205", null, java.util.Arrays.asList(new String[]{"9015cd45-0d06-4b25-a859-cb0bec579c00"}));
Objectc28a2a92c669b3ddb6aa0b32 schema4 = new Objectc28a2a92c669b3ddb6aa0b32("3ee13dde-5d44-47b4-993e-8538e6577e78", "Addison960", null, java.util.Arrays.asList(new String[]{"6523ec13-b1d6-43b3-968c-944872c51c92", "347a389a-9e2e-48d8-a6d5-5532088ebd17", "41da6b73-be29-485c-83a7-6db050d8bd05"}));
Objectc28a2a92c669b3ddb6aa0b32 schema5 = new Objectc28a2a92c669b3ddb6aa0b32("15b4c457-b36d-4871-8940-7a781db120de", "Owen.", "https://images.pexels.com/photos/1125850/pexels-photo-1125850.jpeg", java.util.Arrays.asList(new String[]{"6e433036-4193-4108-a551-54ad8aaeb0c9", "02c130da-0b48-44b5-8084-e6c5bc3139bd", "10470636-a646-4a62-825a-b7988d0d12a2"}));
schema.add(schema1);
schema.add(schema2);
schema.add(schema3);
schema.add(schema4);
schema.add(schema5);
}
}
Objectc28a2a92c669b3ddb6aa0b32.java
public class Objectc28a2a92c669b3ddb6aa0b32{
private String id;
private String username;
private Object image;
private java.util.List<String> posts;
public Objectc28a2a92c669b3ddb6aa0b32(String id, String username, Object image, java.util.List<String> posts){
this.id = id;
this.username = username;
this.image = image;
this.posts = posts;
}
}