toml4j
toml4j copied to clipboard
Converting Java Object to TOML File taking variable name instead of serializable name
We are converting Java Object into TOML File. Our Java POJO class variables are annotated with @SerializedName but while conversion the name of the variable is written in the toml file instead of the serialized name.
variable name _package as package is reserve keyword in Java. The serializable name is a package. Similarly for cveId should be serialized with name cve-id while writing POJO to toml.
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import com.google.gson.annotations.SerializedName;
import com.moandjiezana.toml.TomlWriter;
public class Allow {
@SerializedName("cve-id")
private String cveId;
@SerializedName("package")
private String _package;
@SerializedName("versions")
private List<String> versions = null;
public String getCveId() {
return cveId;
}
public void setCveId(String cveId) {
this.cveId = cveId;
}
public String getPackage() {
return _package;
}
public void setPackage(String _package) {
this._package = _package;
}
public List<String> getVersions() {
return versions;
}
public void setVersions(List<String> versions) {
this.versions = versions;
}
public static void main(String[] args) {
TomlWriter tomlWriter = new TomlWriter();
Allow allow = new Allow();
allow.setCveId("CVE-2020-11104");
allow.setPackage("cereal11");
allow.setVersions(Arrays.asList("1.3.0"));
try {
tomlWriter.write(allow, new File("C:\\Users\\allow.toml"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Output - cveId = "CVE-2020-11104" _package = "cereal11" versions = ["1.3.0"]
Expected Output - cve-id = "CVE-2020-11104" package = "cereal11" versions = ["1.3.0"]
Hi, it seems that the author is not maintaining this lib anymore, I've also requested some input but unfortunately nothing.
Yes right @smamusa I have opted for a workaround for now to overcome this problem.
Has this problem been solved?