1

I have a project in spring and lombok. I have the following class:

import lombok.Value;

@Value
public class Movement {

int xAxis;

int yAxis;

}

This is being returned in a spring response. However I'm expecting it to be returned like this:

"movement": {

 "xAxis":1,
 "yAxis":2
}

but it comes back like this

 "movement": {

  "xaxis":1,
  "yaxis":2
 }

with the fields in lower case. Am I missing something?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Nespony
  • 1,253
  • 4
  • 24
  • 42
  • 3
    Does this answer your question? [Stop Jackson from changing case of variable names](https://stackoverflow.com/questions/46652019/stop-jackson-from-changing-case-of-variable-names) – kasptom Aug 19 '20 at 14:02

2 Answers2

4

Try to use JsonProperty

@Value
public class Movement {

@JsonProperty("xAxis")
int xAxis;

@JsonProperty("yAxis")
int yAxis;

}
Andrew Blagij
  • 236
  • 1
  • 7
0

@JsonProperty Defines name of the logical property, i.e. JSON object field name to use for the property. If value is empty String (which is the default), will try to use name of the field that is annotated.

Use this annotation as per below :

@JsonProperty("xAxis")
int xAxis;
vivekbhatt
  • 26
  • 3