Home > other >  is there a way to create a java class lombok field with a period or other custom character?
is there a way to create a java class lombok field with a period or other custom character?

Time:05-07

How can I make a field name have a period in it? Why? Because this eventually gets translated into JSON that is passed to a service, and the field needs to have a value that is not acceptable as a Java variable, so this isn't working. Thanks!

public class PyPiDTO {

    private String packageName;

    # Not working
    private String park.driver.maxResultSize;
}

CodePudding user response:

You cannot and at the end you should not. Depending on the JSON library you are using, you may use a different property name for the JSON format. Using Jackson this would work adding the following annotation to the field @JsonProperty("park.driver.maxResultSize")

CodePudding user response:

As per Java specification, dot('.') is not valid character for identifier name. So you may not be able to use that character for your member variable.

So even lombok may not be helpful for your case.

However you might want to have look for this SO link if that is helpful for you.

  • Related