Java

Overview

The Java Generator produces java class files from a linkml model, with optional support for user-supplied jinja2 templates to generate classes with alternate annotations or additional documentation.

Docs

Command Line

Code

Additional Notes

The Java generator’s default template uses Project Lombok’s @Data annotation, which provides getters, setters, equals and hashcode functionality.

Alternate Template Example

Here is an alternate template using Hibernate JPA annotations, named example_template.java.jinja2

package {{ doc.package }};

import java.util.List;
import lombok.*;
import javax.persistence.*;
import org.hibernate.search.engine.backend.types.*;
import org.hibernate.envers.Audited;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.*;


@Audited
@Indexed
@Entity
@Data @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true)
public class {{ cls.name }} {% if cls.is_a -%} extends {{ cls.is_a }} {%- endif %} {
{% for f in cls.fields %}
  private {{f.range}} {{ f.name }};
{%- endfor %}

}

The alternate template for the generator can be specified with the –template_file option

gen-java --package org.biolink.model --output_directory org/biolink/model \
         --template_file example_template.java.jinja2 biolink-model.yaml