-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* jax-rs support * fix error: reference not found
- Loading branch information
Showing
24 changed files
with
1,146 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.alibaba.fastjson2</groupId> | ||
<artifactId>fastjson2-extension-jaxrs</artifactId> | ||
<version>2.0.54-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>fastjson2-extension-jaxrs-jakarta</artifactId> | ||
|
||
<properties> | ||
<java.version>11</java.version> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target> | ||
|
||
<jersey.version>3.1.0</jersey.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.core</groupId> | ||
<artifactId>jersey-common</artifactId> | ||
<version>${jersey.version}</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.ws.rs</groupId> | ||
<artifactId>jakarta.ws.rs-api</artifactId> | ||
<version>${jakarta.ws.rs.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- test dependencies --> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.inject</groupId> | ||
<artifactId>jersey-hk2</artifactId> | ||
<version>${jersey.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.test-framework.providers</groupId> | ||
<artifactId>jersey-test-framework-provider-jdk-http</artifactId> | ||
<version>${jersey.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.skyscreamer</groupId> | ||
<artifactId>jsonassert</artifactId> | ||
<version>1.5.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
36 changes: 36 additions & 0 deletions
36
.../src/main/java/com/alibaba/fastjson2/support/jaxrs/jakarta/FastJson2AutoDiscoverable.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,36 @@ | ||
package com.alibaba.fastjson2.support.jaxrs.jakarta; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.ws.rs.core.Configuration; | ||
import jakarta.ws.rs.core.FeatureContext; | ||
import org.glassfish.jersey.internal.spi.AutoDiscoverable; | ||
|
||
/** | ||
* FastJson2AutoDiscoverable | ||
* 参考: com.alibaba.fastjson.support.jaxrs.FastJsonAutoDiscoverable | ||
* | ||
* @author 张治保 | ||
* @since 2024/10/16 | ||
* @see AutoDiscoverable | ||
*/ | ||
@Priority(AutoDiscoverable.DEFAULT_PRIORITY - 1) | ||
public class FastJson2AutoDiscoverable | ||
implements AutoDiscoverable { | ||
public static final String FASTJSON_AUTO_DISCOVERABLE = "fastjson.auto.discoverable"; | ||
public static volatile boolean autoDiscover; | ||
|
||
static { | ||
autoDiscover = Boolean.parseBoolean( | ||
System.getProperty(FASTJSON_AUTO_DISCOVERABLE, Boolean.TRUE.toString())); | ||
} | ||
|
||
@Override | ||
public void configure(final FeatureContext context) { | ||
final Configuration config = context.getConfiguration(); | ||
|
||
// Register FastJson. | ||
if (!config.isRegistered(FastJson2Feature.class) && autoDiscover) { | ||
context.register(FastJson2Feature.class); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...s-jakarta/src/main/java/com/alibaba/fastjson2/support/jaxrs/jakarta/FastJson2Feature.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,60 @@ | ||
package com.alibaba.fastjson2.support.jaxrs.jakarta; | ||
|
||
import jakarta.ws.rs.core.Configuration; | ||
import jakarta.ws.rs.core.Feature; | ||
import jakarta.ws.rs.core.FeatureContext; | ||
import jakarta.ws.rs.ext.MessageBodyReader; | ||
import jakarta.ws.rs.ext.MessageBodyWriter; | ||
import org.glassfish.jersey.CommonProperties; | ||
import org.glassfish.jersey.internal.InternalProperties; | ||
import org.glassfish.jersey.internal.util.PropertiesHelper; | ||
/** | ||
* FastJson2Feature | ||
* 参考:com.alibaba.fastjson.support.jaxrs.FastJsonFeature | ||
* | ||
* @author 张治保 | ||
* @since 2024/10/16 | ||
* @see Feature | ||
*/ | ||
public class FastJson2Feature | ||
implements Feature { | ||
private static final String JSON_FEATURE = FastJson2Feature.class.getSimpleName(); | ||
|
||
@Override | ||
public boolean configure(final FeatureContext context) { | ||
try { | ||
final Configuration config = context.getConfiguration(); | ||
|
||
final String jsonFeature = CommonProperties.getValue( | ||
config.getProperties(), | ||
config.getRuntimeType(), | ||
InternalProperties.JSON_FEATURE, | ||
JSON_FEATURE, | ||
String.class | ||
); | ||
|
||
// Other JSON providers registered. | ||
if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) { | ||
return false; | ||
} | ||
|
||
// Disable other JSON providers. | ||
context.property( | ||
PropertiesHelper.getPropertyNameForRuntime( | ||
InternalProperties.JSON_FEATURE, | ||
config.getRuntimeType() | ||
), | ||
JSON_FEATURE | ||
); | ||
|
||
// Register FastJson. | ||
if (!config.isRegistered(FastJson2Provider.class)) { | ||
context.register(FastJson2Provider.class, MessageBodyReader.class, MessageBodyWriter.class); | ||
} | ||
} catch (NoSuchMethodError e) { | ||
// skip | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.