We have a REST web service implemented with the Jersey framework that allows users to save configuration info from the UI. There is a GET (to get current config info) and a corresponding POST to save settings. That data is saved in a JSON file. The GET works perfectly, as does the POST exept for one value:
"modulation": 2,
No matter what this value is set to, when getting the data from the UI in the POST, it's always the default. Every other value is perfect.
This value used to be an enum and since everything in the file is saved as an int
or String
, I thought that might be confusing it. So I changed it to an int
. That didn't help. On the bright side, it didn't make anything worse either.
Using good ol' Postman, I send a JSON structure with the POST:
{
"customers": {
"max": 20,
"current": 2
},
"window": {
"x": 10,
"y": 10,
"width": 20,
"height": 20
},
"modulation": 2, // always just the default, 1
"pointsOfConsternation": 20
}
It gets automagically converted into an object that we use for configuration. All the values come across correctly except that pesky mode
. Here is what the receiving method signature looks like:
@POST
@Consumes({MediaType.APPLICATION_JSON})
@Produces(MediaType.TEXT_PLAIN)
@Path("/config")
public String setConfiguration( ConsternationConfig config ) {
...
// do magic
...
}
I've debugged the crap out of it to no avail. The mangling happens in code that I don't have any control over. It comes into the POST method mangled.
Any idea on what might be going on?
UPDATE
Per @Aleh Maksimovich, here is the source for ConsternationConfig
:
@XmlRootElement
public class ConsternationConfig {
// Data members
private Customers customers;
// private ConsternationModulation modulation; // how modulation used to be defined, changed to the int below
private int modulation;
private int pointsOfConsternation;
@XmlJavaTypeAdapter(RectangleStandInAdapter.class)
private Rectangle window;
/**
* Default constructor
*/
public ConsternationConfig() {
customers = new Customers();
// modulation = DEFAULT_MODULATION; // how modulation used to be defined
modulation = DEFAULT_MODULATION.ordinal();
pointsOfConsternation= DEFAULT_POINTS_OF_CONSTERNATION;
window = new Rectangle(DEFAULT_WINDOW_X, DEFAULT_WINDOW_Y, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
}
public ConsternationModulation getModulation() {
return ConsternationModulation.values()[modulation];
}
public void setModulation(int modulation) {
this.modulation = modulation;
}
public void setModulation(ConsternationModulation modulation) {
this.modulation = modulation.ordinal();
}
...a whole bunch of other getters and setters that do nothing but set individual members...
}
And here's ConsternationModulation
just for good measure:
public enum ConsternationModulation {
INVALID,
FIRST_CONSTERNATION,
SECOND_CONSTERNATION,
THIRD_CONSTERNATION,
FOURTH_CONSTERNATION
}