diff --git a/hibernate-orm-rest-data-panache-quickstart/src/main/java/org/acme/hibernate/orm/panache/rest/entity/Person.java b/hibernate-orm-rest-data-panache-quickstart/src/main/java/org/acme/hibernate/orm/panache/rest/entity/Person.java index 2fb7bc0c3c..59d76d6d31 100644 --- a/hibernate-orm-rest-data-panache-quickstart/src/main/java/org/acme/hibernate/orm/panache/rest/entity/Person.java +++ b/hibernate-orm-rest-data-panache-quickstart/src/main/java/org/acme/hibernate/orm/panache/rest/entity/Person.java @@ -1,6 +1,10 @@ package org.acme.hibernate.orm.panache.rest.entity; import java.time.LocalDate; +import java.util.Map; + +import org.hibernate.annotations.JdbcTypeCode; +import org.hibernate.type.SqlTypes; import jakarta.persistence.Entity; import jakarta.persistence.NamedQuery; @@ -12,4 +16,7 @@ public class Person extends PanacheEntity { public String name; public LocalDate birthDate; + + @JdbcTypeCode(SqlTypes.JSON) + public Map jsonAddress; } diff --git a/hibernate-orm-rest-data-panache-quickstart/src/test/java/org/acme/hibernate/orm/panache/rest/entity/PeopleResourceTest.java b/hibernate-orm-rest-data-panache-quickstart/src/test/java/org/acme/hibernate/orm/panache/rest/entity/PeopleResourceTest.java index e7491330ee..c167158154 100644 --- a/hibernate-orm-rest-data-panache-quickstart/src/test/java/org/acme/hibernate/orm/panache/rest/entity/PeopleResourceTest.java +++ b/hibernate-orm-rest-data-panache-quickstart/src/test/java/org/acme/hibernate/orm/panache/rest/entity/PeopleResourceTest.java @@ -6,6 +6,10 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; +import java.time.LocalDate; +import java.util.HashMap; +import java.util.Map; + import org.apache.http.HttpStatus; import org.junit.jupiter.api.Test; @@ -113,4 +117,30 @@ void shouldDeleteNotBeExposed() { given().when().delete("/my-people/1") .then().statusCode(405); } + + @Test + void shouldUpdatePerson() { + + Person newPerson = new Person(); + newPerson.name = "Holly"; + newPerson.birthDate = LocalDate.of(2001, 11, 20); + + Map jsonObject = new HashMap<>(); + jsonObject.put("zipcode", 95014); + jsonObject.put("city", "cupertino"); + newPerson.jsonAddress = jsonObject; + + given().accept(ContentType.JSON).and().contentType(ContentType.JSON).and().body(newPerson).when() + .put("/my-people/1").then().statusCode(204); + + // verify after updating that the new json address fields were stored + given().accept(ContentType.JSON) + .when().get("/my-people/1") + .then().statusCode(200) + .and().body("id", is(equalTo(1))) + .and().body("name", is(equalTo("Holly"))) + .and().body("jsonAddress", is( equalTo(jsonObject))); + + } + }