public class JsonExporter extends Object implements Product.Exporter
This class is used when we want to export the state of a Product for use in a different context or format.
A JsonExporter object can, produce a String with the Json representing a Product.
Typical usage:
Product p1 = new Product.Builder() .name("Renat") .price(209.00) .alcohol(37.50) .volume(700) .nr(101) .productGroup("Okryddad sprit") .build(); JsonExporter jsonExp = new JsonExporter(); p1.export(jsonExp); System.out.println(jsonExp.toJsonString());The above will print (on a single line): // note: should we say productGroup or product_group?
{ "name": "Renat", "price": 209.00, "alcohol": 37.50, "volume": 700, "nr": 101, "product_group": "Okryddad sprit" }
Constructor and Description |
---|
JsonExporter() |
Modifier and Type | Method and Description |
---|---|
void |
addAlcohol(double alcohol) |
void |
addName(String name) |
void |
addNr(int nr) |
void |
addPrice(double price) |
void |
addProductGroup(String productGroup) |
void |
addType(String type) |
void |
addVolume(int volume) |
String |
toJsonString()
Returns a String with a Json representation of an object.
|
String |
toString()
Returns the exported Product as a plain String
for debuggin purposes
|
public void addName(String name)
addName
in interface Product.Exporter
public void addPrice(double price)
addPrice
in interface Product.Exporter
public void addAlcohol(double alcohol)
addAlcohol
in interface Product.Exporter
public void addVolume(int volume)
addVolume
in interface Product.Exporter
public void addNr(int nr)
addNr
in interface Product.Exporter
public void addProductGroup(String productGroup)
addProductGroup
in interface Product.Exporter
public void addType(String type)
addType
in interface Product.Exporter
public String toString()
public String toJsonString()