forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow JSON serialization customization in ORM
- add a property to pass a custom FormatMapper for JSON formatting - use a Quarkus-configured ObjectMapper if Jackson is present and user did not specify a format mapper
- Loading branch information
1 parent
acaa257
commit 5d3e509
Showing
14 changed files
with
297 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...me/src/main/java/io/quarkus/hibernate/orm/runtime/customized/QuarkusJsonFormatMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkus.hibernate.orm.runtime.customized; | ||
|
||
import org.hibernate.type.descriptor.WrapperOptions; | ||
import org.hibernate.type.descriptor.java.JavaType; | ||
import org.hibernate.type.format.FormatMapper; | ||
import org.hibernate.type.format.jackson.JacksonJsonFormatMapper; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import io.quarkus.arc.Arc; | ||
|
||
public class QuarkusJsonFormatMapper implements FormatMapper { | ||
private final FormatMapper delegate = new JacksonJsonFormatMapper(Arc.container().instance(ObjectMapper.class).get()); | ||
|
||
public <T> T fromString(CharSequence charSequence, JavaType<T> javaType, WrapperOptions wrapperOptions) { | ||
return delegate.fromString(charSequence, javaType, wrapperOptions); | ||
} | ||
|
||
public <T> String toString(T value, JavaType<T> javaType, WrapperOptions wrapperOptions) { | ||
return delegate.toString(value, javaType, wrapperOptions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ation-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/EntityWithJson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.quarkus.it.jpa.postgresql; | ||
|
||
import java.time.LocalDate; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
|
||
import org.hibernate.annotations.JdbcTypeCode; | ||
import org.hibernate.type.SqlTypes; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
|
||
@Entity | ||
public class EntityWithJson { | ||
@Id | ||
@GeneratedValue | ||
Long id; | ||
|
||
@JdbcTypeCode(SqlTypes.JSON) | ||
ToBeJsonWithDateTime json; | ||
|
||
public EntityWithJson() { | ||
} | ||
|
||
public EntityWithJson(ToBeJsonWithDateTime json) { | ||
this.json = json; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "EntityWithJson{" + | ||
"id=" + id + | ||
", json=" + json + | ||
'}'; | ||
} | ||
|
||
@RegisterForReflection | ||
public static class ToBeJsonWithDateTime { | ||
@JsonProperty | ||
LocalDate date; | ||
|
||
public ToBeJsonWithDateTime() { | ||
} | ||
|
||
public ToBeJsonWithDateTime(LocalDate date) { | ||
this.date = date; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ToBeJsonWithDateTime{" + | ||
"date=" + date + | ||
'}'; | ||
} | ||
} | ||
} |
Oops, something went wrong.