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

  1. In Product add a new backorderAvailable property

  2. Create a new class in the edu.train package named BooleanToStringConverter

  3. Make the new BooleanToStringConverter class implement the AttributeConverter interface using type parameters Boolean and String

  4. Since we don't want to apply the converter globally, add the converter directly to the backorderAvailable property in the Product class

Verification

  1. Start the training application and go to the app home page

  2. Click on the product link and verify it has a backorderAvailable property

    "name" : "Basketball", "quantity" : 5, "backorderAvailable" : true

  3. Use the H2 database viewer to confirm the information is stored as a string value