-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use newer JSON-P & JSON-B standards as alternative to Jackson, fixes #29 #112
Draft
jwgmeligmeyling
wants to merge
1
commit into
vladmihalcea:master
Choose a base branch
from
jwgmeligmeyling:feature/29
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,764
−62
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
77 changes: 77 additions & 0 deletions
77
hibernate-types-52/src/main/java/com/vladmihalcea/hibernate/type/jsonp/JsonBinaryType.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,77 @@ | ||
package com.vladmihalcea.hibernate.type.jsonp; | ||
|
||
import com.vladmihalcea.hibernate.type.AbstractHibernateType; | ||
import com.vladmihalcea.hibernate.type.jsonp.internal.JsonBinarySqlTypeDescriptor; | ||
import com.vladmihalcea.hibernate.type.jsonp.internal.JsonTypeDescriptor; | ||
import com.vladmihalcea.hibernate.type.jsonp.internal.JsonbUtil; | ||
import com.vladmihalcea.hibernate.type.util.Configuration; | ||
import com.vladmihalcea.hibernate.type.util.JsonbWrapper; | ||
import org.hibernate.usertype.DynamicParameterizedType; | ||
|
||
import javax.json.bind.Jsonb; | ||
import java.lang.reflect.Type; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Maps any given Java object on a JSON column type that is managed via {@link java.sql.PreparedStatement#setObject(int, Object)} at JDBC Driver level. For instance, if you are using PostgreSQL, you should be using this {@link JsonBinaryType} to map both {@code jsonb} and {@code json} column types. | ||
* <p> | ||
* | ||
* @author Jan-Willem Gmelig Meyling | ||
*/ | ||
public class JsonBinaryType extends AbstractHibernateType<Object> implements DynamicParameterizedType { | ||
|
||
public static final JsonBinaryType INSTANCE = new JsonBinaryType(); | ||
|
||
public JsonBinaryType() { | ||
super( | ||
JsonBinarySqlTypeDescriptor.INSTANCE, | ||
new JsonTypeDescriptor(JsonbUtil.getObjectMapperWrapper(Configuration.INSTANCE)) | ||
); | ||
} | ||
|
||
public JsonBinaryType(Configuration configuration) { | ||
super( | ||
JsonBinarySqlTypeDescriptor.INSTANCE, | ||
new JsonTypeDescriptor(JsonbUtil.getObjectMapperWrapper(configuration)), | ||
configuration | ||
); | ||
} | ||
|
||
public JsonBinaryType(Jsonb objectMapper) { | ||
super( | ||
JsonBinarySqlTypeDescriptor.INSTANCE, | ||
new JsonTypeDescriptor(new JsonbWrapper(objectMapper)) | ||
); | ||
} | ||
|
||
public JsonBinaryType(JsonbWrapper jsonbWrapper) { | ||
super( | ||
JsonBinarySqlTypeDescriptor.INSTANCE, | ||
new JsonTypeDescriptor(jsonbWrapper) | ||
); | ||
} | ||
|
||
public JsonBinaryType(Jsonb objectMapper, Type javaType) { | ||
super( | ||
JsonBinarySqlTypeDescriptor.INSTANCE, | ||
new JsonTypeDescriptor(new JsonbWrapper(objectMapper), javaType) | ||
); | ||
} | ||
|
||
public JsonBinaryType(JsonbWrapper jsonbWrapper, Type javaType) { | ||
super( | ||
JsonBinarySqlTypeDescriptor.INSTANCE, | ||
new JsonTypeDescriptor(jsonbWrapper, javaType) | ||
); | ||
} | ||
|
||
public String getName() { | ||
return "jsonb-p"; | ||
} | ||
|
||
@Override | ||
public void setParameterValues(Properties parameters) { | ||
((JsonTypeDescriptor) getJavaTypeDescriptor()).setParameterValues(parameters); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
...nate-types-52/src/main/java/com/vladmihalcea/hibernate/type/jsonp/JsonNodeBinaryType.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,54 @@ | ||
package com.vladmihalcea.hibernate.type.jsonp; | ||
|
||
import com.vladmihalcea.hibernate.type.AbstractHibernateType; | ||
import com.vladmihalcea.hibernate.type.jsonp.internal.JsonBinarySqlTypeDescriptor; | ||
import com.vladmihalcea.hibernate.type.jsonp.internal.JsonNodeTypeDescriptor; | ||
import com.vladmihalcea.hibernate.type.jsonp.internal.JsonbUtil; | ||
import com.vladmihalcea.hibernate.type.util.Configuration; | ||
import com.vladmihalcea.hibernate.type.util.JsonbWrapper; | ||
|
||
import javax.json.JsonValue; | ||
import javax.json.bind.Jsonb; | ||
|
||
/** | ||
* Maps a Json-P {@link JsonValue} object on a JSON column type that is managed via {@link java.sql.PreparedStatement#setObject(int, Object)} at JDBC Driver level. For instance, if you are using PostgreSQL, you should be using {@link JsonNodeBinaryType} to map both {@code jsonb} and {@code json} column types to a Jackson {@link JsonNode} object. | ||
* | ||
* @author Jan-Willem Gmelig Meyling | ||
*/ | ||
public class JsonNodeBinaryType extends AbstractHibernateType<JsonValue> { | ||
|
||
public static final JsonNodeBinaryType INSTANCE = new JsonNodeBinaryType(); | ||
|
||
public JsonNodeBinaryType() { | ||
super( | ||
JsonBinarySqlTypeDescriptor.INSTANCE, | ||
new JsonNodeTypeDescriptor(JsonbUtil.getObjectMapperWrapper(Configuration.INSTANCE)) | ||
); | ||
} | ||
|
||
public JsonNodeBinaryType(Configuration configuration) { | ||
super( | ||
JsonBinarySqlTypeDescriptor.INSTANCE, | ||
new JsonNodeTypeDescriptor(JsonbUtil.getObjectMapperWrapper(configuration)), | ||
configuration | ||
); | ||
} | ||
|
||
public JsonNodeBinaryType(Jsonb objectMapper) { | ||
super( | ||
JsonBinarySqlTypeDescriptor.INSTANCE, | ||
new JsonNodeTypeDescriptor(new JsonbWrapper(objectMapper)) | ||
); | ||
} | ||
|
||
public JsonNodeBinaryType(JsonbWrapper jsonbWrapper) { | ||
super( | ||
JsonBinarySqlTypeDescriptor.INSTANCE, | ||
new JsonNodeTypeDescriptor(jsonbWrapper) | ||
); | ||
} | ||
|
||
public String getName() { | ||
return "jsonb-p-value"; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is better named
JsonValueBinaryType