use of mekanism.api.chemical.ChemicalType in project Mekanism by mekanism.
the class SerializerHelper method getChemicalType.
/**
* Gets and deserializes a Chemical Type from a given Json Object.
*
* @param json Json Object.
*
* @return Chemical Type.
*/
public static ChemicalType getChemicalType(@Nonnull JsonObject json) {
if (!json.has(JsonConstants.CHEMICAL_TYPE)) {
throw new JsonSyntaxException("Missing '" + JsonConstants.CHEMICAL_TYPE + "', expected to find a string");
}
JsonElement element = json.get(JsonConstants.CHEMICAL_TYPE);
if (!element.isJsonPrimitive()) {
throw new JsonSyntaxException("Expected '" + JsonConstants.CHEMICAL_TYPE + "' to be a json primitive representing a string");
}
String name = element.getAsString();
ChemicalType chemicalType = ChemicalType.fromString(name);
if (chemicalType == null) {
throw new JsonSyntaxException("Invalid chemical type '" + name + "'.");
}
return chemicalType;
}
Aggregations