Skip to content

Commit

Permalink
Include JSONB example in hibernate quickstart
Browse files Browse the repository at this point in the history
Example to clarify Quarkus issue # 36730

Include JSONB example

Example to clarify Quarkus issue # 36730
  • Loading branch information
sfali16 committed Nov 1, 2023
1 parent 6af12d5 commit e479011
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,4 +16,7 @@
public class Person extends PanacheEntity {
public String name;
public LocalDate birthDate;

@JdbcTypeCode(SqlTypes.JSON)
public Map<String, Object> jsonAddress;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String, Object> 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)));

}

}

0 comments on commit e479011

Please sign in to comment.