Skip to content

Bio Enum Basics

Rajab Davudov edited this page Mar 13, 2019 · 2 revisions

Bio Enums

You can also define enums inside dictionary. These enums can be used as tags and will be serialized as integers. Also enum values can be exported/parsed from XML/JSON.

Bio Enums are classes and must extends com.linkedlogics.bio.BioEnum. Since Bio Enums are treated as numbers in Bio Expressions, this inheritance is required.

Note that class BioEnum extends Number.

For example:

@BioEnumObj
public class EngineType extends BioEnum {
    public EngineType(int ordinal, String name) {
        super(ordinal, name);
    }
	
    public final static EngineType VEE = new EngineType(0, "vee");
    public final static EngineType INLINE = new EngineType(1, "inline");
    public final static EngineType ROTARY = new EngineType(2, "rotary");
}

Serialization

Bio Enums are serialized as integers. Also they act as numbers in many places, especially in Bio Expressions.

XML Processing

Bio Enums are exported with their string representation and parsed also based on string value.

<?xml version="1.0" encoding="UTF-8"?>
<car type="Car" code="28201">
    <engine type="Engine" code="20998">
        <capacity type="Integer">3200</capacity>
        <engine-type type="EngineType">vee</engine-type>
        <horse-power type="Integer">250</horse-power>
        <number-of-cylinders type="Integer">6</number-of-cylinders>
    </engine>
    <is-new-car type="Boolean">false</is-new-car>
    <producer type="String">Toyota</producer>
    <year-of-production type="Integer">2007</year-of-production>
</car>

Here engine_type is enum and printed its string representation.

JSON Processing

Same applies to JSON which is string representation is used in JSON.

{
    "engine": {
        "horse_power": 250,
        "engine_type": "vee",
        "number_of_cylinders": 6,
        "capacity": 3200
    },
    "producer": "Toyota",
    "year_of_production": 2007,
    "is_new_car": false
}