org.zodiac.sentinel.base.config.configurer.SentinelJsonConfigurer Maven / Gradle / Ivy
package org.zodiac.sentinel.base.config.configurer;
import org.zodiac.sdk.toolkit.util.ObjectUtil;
import org.zodiac.sentinel.base.datasource.converter.JsonSentinelDataSourceConverter;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
import com.alibaba.csp.sentinel.slots.system.SystemRule;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
public class SentinelJsonConfigurer {
private ObjectMapper objectMapper;
public SentinelJsonConfigurer() {
this(null);
}
public SentinelJsonConfigurer(ObjectMapper objectMapper) {
this.objectMapper = ObjectUtil.defaultIfNull(objectMapper, new ObjectMapper());
this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
public JsonSentinelDataSourceConverter jsonFlowConverter() {
return new JsonSentinelDataSourceConverter(objectMapper, FlowRule.class);
}
public JsonSentinelDataSourceConverter jsonDegradeConverter() {
return new JsonSentinelDataSourceConverter(objectMapper, DegradeRule.class);
}
public JsonSentinelDataSourceConverter jsonSystemConverter() {
return new JsonSentinelDataSourceConverter(objectMapper, SystemRule.class);
}
public JsonSentinelDataSourceConverter jsonAuthorityConverter() {
return new JsonSentinelDataSourceConverter(objectMapper, AuthorityRule.class);
}
public JsonSentinelDataSourceConverter jsonParamFlowConverter() {
return new JsonSentinelDataSourceConverter(objectMapper, ParamFlowRule.class);
}
}