![JAR search and dependency download from the Maven repository](/logo.png)
com.alibaba.fastjson.support.jaxrs.FastJsonFeature Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fastjson-to-easyjson Show documentation
Show all versions of fastjson-to-easyjson Show documentation
Adapter alibaba fastjson to other json libraries. the fastjson version: 1.2.58
package com.alibaba.fastjson.support.jaxrs;
import org.glassfish.jersey.CommonProperties;
import org.glassfish.jersey.internal.InternalProperties;
import org.glassfish.jersey.internal.util.PropertiesHelper;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.MessageBodyWriter;
/**
* Title: FastJsonFeature
* Description: FastJsonFeature
*
* @author Victor.Zxy
* @see Feature
* @since 1.2.37
*/
public class FastJsonFeature implements Feature {
private final static String JSON_FEATURE = FastJsonFeature.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(FastJsonProvider.class)) {
context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
}
} catch (NoSuchMethodError e) {
// skip
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy