I want to create a json object with values of "3D Tour", "Videos", "Photos Only", etc. You can find the enum class below. How can I implement that?
package com.padgea.listing.application.dto;
public enum General implements Catalogue {
Tour("3D Tour"),
Videos("Videos"),
Photos_Only("Photos Only"),
Price_Reduced("Price Reduced"),
Furnished("Furnished"),
Luxury("Luxury");
private final String value;
General(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
I need a output like this
{General : "3D Tour","Videos","Photos Only",etc}
>Solution :
This will return a list of strings containing all the values.
enum General implements Catalogue {
Tour("3D Tour"),
Videos("Videos"),
Photos_Only("Photos Only"),
Price_Reduced("Price Reduced"),
Furnished("Furnished"),
Luxury("Luxury");
private final String value;
General(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public static List<String> valuesList() {
return Arrays.stream(General.values())
.map(General::getValue)
.collect(Collectors.toList());
}
}
And a level up you’ll do something like
myJson.put("General", General.valuesList())
An output will be
{
"General": ["3D Tour","Videos","Photos Only"]
}