Skip to content

Bio Objects Basics

Rajab Davudov edited this page Apr 4, 2019 · 9 revisions

Quick Start

Bio Objects can be defined using @annotations or using XML configuration. Here is an example:

@BioObj
public class Car extends BioObject {
  @BioTag(type="Integer")
  public static final String YEAR_OF_PRODUCTION = "year_of_production" ;
  @BioTag(type="String")
  public static final String PRODUCER = "producer" ;
  @BioTag(type="Double")
  public static final String FUEL_EFFICIENCY = "fuel_efficiency" ;
}

Here we annotate a class Car which extends BioObject by annotation @BioObj and also we annotate its fields which will be used in serialization, xml/json mapping, formatting etc. by an annotation @BioTag.

First of all we need to create dictionary which is done by following code. Bio Dictionary finds all annotated classes and fields and give them an id (or code). This code will be used during serialization. It is serializing codes instead of String names.

 new BioDictionaryBuilder().build(); 

also you can specify package root for Bio Objects traversal.

new BioDictionaryBuilder().addPackage("com.linkedlogics.bio.test").build();

After dictionary is created you can instantiate your objects either by default constructor

Car c = new Car() ;

or by dictionary factory methods

Car c = BioDictionary.getDictionary().getFactory().newBioObject(Car.class) ;

Difference is in that second method will use latest concrete class in the dictionary which extends Car and adds some more tags. If you use first method you will get an instance of exact Car class.

You can also provide initial values map as Bio Object to factory method where new Bio Object will contain all those initial values as following:

BioObject initials = new BioObject() ;
initials.set("producer", "Toyota") ;

Car c = BioDictionary.getDictionary().getFactory().newBioObject(Car.class, initials) ;