Exercise 03: Converters - jkneal/spring-angular-train GitHub Wiki
Goals
The Product class needs to have an additional field which indicates whether the product can be backordered. In addition, the field needs to be stored as a string instead of a boolean ('Y' for true and 'N' for false), but should be usable as a boolean in the Java class.
Instructions
-
In
Productadd a newbackorderAvailableproperty -
Create a new class in the
edu.trainpackage namedBooleanToStringConverter -
Make the new
BooleanToStringConverterclass implement the AttributeConverter interface using type parameters Boolean and String -
Since we don't want to apply the converter globally, add the converter directly to the
backorderAvailableproperty in theProductclass
Verification
-
Start the training application and go to the app home page
-
Click on the product link and verify it has a backorderAvailable property
"name" : "Basketball", "quantity" : 5, "backorderAvailable" : true
-
Use the H2 database viewer to confirm the information is stored as a string value