Skip to content

Commit

Permalink
Fix Boolean serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
luneo7 committed Sep 6, 2024
1 parent 75b8a98 commit 3c8e4e3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ String writtenType() {
case "java.lang.Long" -> "long";
case "java.lang.Double" -> "double";
case "java.lang.Float" -> "float";
case "java.lang.Boolean" -> "boolean";
default -> fieldType.name().toString();
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ public class Dog extends AbstractNamedPet {
@JsonProperty("age")
private int publicAge;

@JsonProperty("vaccinated")
private Boolean publicVaccinated;

public int getPublicAge() {
return publicAge;
}

public void setPublicAge(int publicAge) {
this.publicAge = publicAge;
}

public Boolean getPublicVaccinated() {
return publicVaccinated;
}

public void setPublicVaccinated(Boolean publicVaccinated) {
this.publicVaccinated = publicVaccinated;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ public Dog getDog() {
return createDog();
}

@POST
@Path("/dog-echo")
@Consumes(MediaType.APPLICATION_JSON)
public Dog echoDog(Dog dog) {
return dog;
}

@EnableSecureSerialization
@GET
@Path("/abstract-cat")
Expand Down Expand Up @@ -164,6 +171,7 @@ private static Dog createDog() {
dog.setPrivateName("Jack");
dog.setPublicName("Leo");
dog.setVeterinarian(createVeterinarian());
dog.setPublicVaccinated(true);
return dog;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,4 +656,21 @@ private static void testSecuredFieldOnAbstractClass(String catPath, String dogPa
.body("veterinarian.name", Matchers.is("Dolittle"))
.body("veterinarian.title", Matchers.is("VMD"));
}

@Test
public void testEcho() {
RestAssured
.with()
.body("{\"publicName\":\"Leo\",\"veterinarian\":{\"name\":\"Dolittle\"},\"age\":5,\"vaccinated\":true}")
.contentType("application/json; charset=utf-8")
.post("/simple/dog-echo")
.then()
.statusCode(200)
.contentType("application/json")
.body("publicName", Matchers.is("Leo"))
.body("privateName", Matchers.nullValue())
.body("age", Matchers.is(5))
.body("veterinarian.name", Matchers.is("Dolittle"))
.body("veterinarian.title", Matchers.nullValue());
}
}

0 comments on commit 3c8e4e3

Please sign in to comment.