
com.at.avro.formatters.EnumFormatter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of avro-schema-generator Show documentation
Show all versions of avro-schema-generator Show documentation
Library for generating avro schema files (.avsc) based on DB tables structure
package com.at.avro.formatters;
import com.at.avro.config.FormatterConfig;
import com.at.avro.types.Enum;
/**
* @author [email protected]
*/
public class EnumFormatter implements Formatter {
@Override
public String toJson(Enum anEnum, FormatterConfig config) {
String template = "{ \"type\":\"enum\", \"name\":\"%s\", \"symbols\":[%s] }".replaceAll(":", config.colon());
return String.format(template, anEnum.getName(), formatSymbols(anEnum.getSymbols(), config));
}
private String formatSymbols(String[] symbols, FormatterConfig config) {
StringBuilder symbolsJson = new StringBuilder();
if (symbols.length > 0) {
for (String symbol : symbols) {
symbolsJson.append("\"").append(symbol.trim()).append("\", ");
}
symbolsJson.setLength(symbolsJson.length() - 2);
}
return symbolsJson.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy