Review Comments
This commit is contained in:
parent
96ff2a982a
commit
00671fd084
@ -10,12 +10,12 @@ public class BooleanDeserializer extends JsonDeserializer<Boolean> {
|
||||
@Override
|
||||
public Boolean deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
String value = parser.getText();
|
||||
if (value != null && (value.equals("TRUE") || value.equals("1") || value.equals("+"))) {
|
||||
if (value != null && value.equals("+")) {
|
||||
return Boolean.TRUE;
|
||||
} else if (value != null && (value.equals("FALSE") || value.equals("0") || value.equals("-"))) {
|
||||
} else if (value != null && value.equals("-")) {
|
||||
return Boolean.FALSE;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Only values accepted as Boolean are TRUE, FALSE, +, -, 1 , 0");
|
||||
throw new IllegalArgumentException("Only values accepted as Boolean are + and -");
|
||||
}
|
||||
}
|
||||
}
|
@ -84,13 +84,13 @@ class ValidationControllerUnitTest {
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
assertEquals("Only values accepted as Boolean are TRUE, FALSE, +, -, 1 , 0", output);
|
||||
assertEquals("Only values accepted as Boolean are + and -", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvalidBooleanFromJson() throws Exception {
|
||||
|
||||
String postBody = "{\"boolField\":true,\"trueField\":true,\"falseField\":false,\"boolStringVar\":\"6\"}";
|
||||
String postBody = "{\"boolField\":true,\"trueField\":true,\"falseField\":false,\"boolStringVar\":\"plus\"}";
|
||||
|
||||
String output = mockMvc.perform(post("/validateBoolean").contentType("application/json")
|
||||
.content(postBody))
|
||||
@ -98,7 +98,7 @@ class ValidationControllerUnitTest {
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
assertEquals("Only values accepted as Boolean are TRUE, FALSE, +, -, 1 , 0", output);
|
||||
assertEquals("Only values accepted as Boolean are + and -", output);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user