Problems with sonar changing the names of an object in REST calls by Jackson JSON

AntoCode :

I have an object that in its fields is mandatory that some names have '_' for example local_PC instead of localPC.

The problem I have is that I need it to be local_PC and when a call is made to my app they send that field and I can't change it, but sonar launches me error because it must be localPC

Is there any way I can control it by Jackson?

realizing @jsonproperty only allows me to change the names in the output but not in the input of the controller

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@AllArgsConstructor
public class Example{

 private String local_PC;

}
Deadpool :

Use @JsonAlias

@JsonAlias is introduced in Jackson 2.9 release. @JsonAlias defines one or more alternative names for a property to be accepted during deserialization i.e. setting JSON data to Java object. But at the time of serialization i.e. while getting JSON from Java object, only actual logical property name is used and not alias. @JsonAlias

@JsonAlias({"local_PC", "localPC"})
private String local_PC;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=154598&siteId=1