HHH-15415 Jakarta JsonB integration to not break GraalVM native image compilation
This commit is contained in:
parent
ca2088ad39
commit
d363ba6e89
|
@ -71,10 +71,9 @@ import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
|
|||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.stat.Statistics;
|
||||
import org.hibernate.type.FormatMapper;
|
||||
import org.hibernate.type.JacksonJsonFormatMapper;
|
||||
import org.hibernate.type.JaxbXmlFormatMapper;
|
||||
import org.hibernate.type.JsonBJsonFormatMapper;
|
||||
import org.hibernate.type.jackson.JacksonIntegration;
|
||||
import org.hibernate.type.jakartajson.JakartaJsonIntegration;
|
||||
|
||||
import static org.hibernate.cfg.AvailableSettings.ALLOW_JTA_TRANSACTION_ACCESS;
|
||||
import static org.hibernate.cfg.AvailableSettings.ALLOW_REFRESH_DETACHED_ENTITY;
|
||||
|
@ -801,15 +800,9 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
if (jsonJacksonFormatMapper != null) {
|
||||
return jsonJacksonFormatMapper;
|
||||
}
|
||||
try {
|
||||
// Force initialization of the instance
|
||||
JsonBJsonFormatMapper.INSTANCE.hashCode();
|
||||
return JsonBJsonFormatMapper.INSTANCE;
|
||||
else {
|
||||
return JakartaJsonIntegration.getJakartaJsonBFormatMapperOrNull();
|
||||
}
|
||||
catch (NoClassDefFoundError ex) {
|
||||
// Ignore
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.type.jakartajson;
|
||||
|
||||
import org.hibernate.type.FormatMapper;
|
||||
import org.hibernate.type.JsonBJsonFormatMapper;
|
||||
|
||||
public final class JakartaJsonIntegration {
|
||||
|
||||
// Implementation note: we rely on the following two fields to be folded as constants
|
||||
// when GraalVM native image is initializing them.
|
||||
private static final boolean JAKARTA_JSON_AVAILABLE = ableToLoadJakartaJsonB();
|
||||
private static final JsonBJsonFormatMapper JSON_FORMAT_MAPPER = JAKARTA_JSON_AVAILABLE ? new JsonBJsonFormatMapper() : null;
|
||||
|
||||
private JakartaJsonIntegration() {
|
||||
//To not be instantiated: static helpers only
|
||||
}
|
||||
|
||||
private static boolean ableToLoadJakartaJsonB() {
|
||||
try {
|
||||
JakartaJsonIntegration.class.getClassLoader().loadClass( "jakarta.json.bind.Jsonb" );
|
||||
return true;
|
||||
}
|
||||
catch (ClassNotFoundException | LinkageError e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static FormatMapper getJakartaJsonBFormatMapperOrNull() {
|
||||
return JSON_FORMAT_MAPPER;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue