Skip to content

Formatting

Rajab Davudov edited this page Jun 20, 2019 · 3 revisions

Formatting

Since Bio Objects are maps we can put any type of value inside. Sometimes these values' types do not match with the dictionary. For example, if year_of_production is Integer but we can put it as String. Especially parsed from HTTP request all parameters will be strings. It will be difficult to convert all strings into correct types as in dictionary.

format()

format() method solves above problem. You only need to call this method and rest will be handled by itself.

Car c = new Car() ;
c.set(Car.PRODUCER, "Ford") ;
c.set(Car.YEAR_OF_PRODUCTION, "2019") ;
c.set(Car.FUEL_EFFICIENCY, "17.8") ;
c.format();
System.out.println(c.toXml()) ; 

All string values are converted to correct types. It actually applies not only to strings. Doubles can also be converted (casted) to Integers etc.

<?xml version="1.0" encoding="UTF-8"?>
<car type="Car" code="28201">
    <fuel-efficiency type="Double">17.8</fuel-efficiency>
    <producer type="String">Ford</producer>
    <year-of-production type="Integer">2019</year-of-production>
</car>