toml4j icon indicating copy to clipboard operation
toml4j copied to clipboard

Converting Java Object to TOML File taking variable name instead of serializable name

Open swapnilgangrade01 opened this issue 3 years ago • 3 comments

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"]

swapnilgangrade01 avatar Sep 28 '21 11:09 swapnilgangrade01

Hi, it seems that the author is not maintaining this lib anymore, I've also requested some input but unfortunately nothing.

stjepanmamusa avatar Sep 30 '21 16:09 stjepanmamusa

Yes right @smamusa I have opted for a workaround for now to overcome this problem.

swapnilgangrade01 avatar Oct 28 '21 13:10 swapnilgangrade01

Has this problem been solved?

sarimmehdi avatar Dec 03 '21 14:12 sarimmehdi