本文整理汇总了Java中com.fasterxml.jackson.databind.module.SimpleModule类的典型用法代码示例。如果您正苦于以下问题:Java SimpleModule类的具体用法?Java SimpleModule怎么用?Java SimpleModule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleModule类属于com.fasterxml.jackson.databind.module包,在下文中一共展示了SimpleModule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
@Before public void setUp() {
SimpleModule module = new SimpleModule();
module.addSerializer(AnInterface.class, new AnInterfaceSerializer());
module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer());
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);
mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
mapper.setVisibilityChecker(mapper.getSerializationConfig()
.getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY));
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(JacksonConverterFactory.create(mapper))
.build();
service = retrofit.create(Service.class);
}
示例2: read
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
public static SecurityAnalysisResult read(Path jsonFile) {
Objects.requireNonNull(jsonFile);
try (InputStream is = Files.newInputStream(jsonFile)) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
SimpleModule module = new SimpleModule();
module.addDeserializer(SecurityAnalysisResult.class, new SecurityAnalysisResultDeserializer());
module.addDeserializer(NetworkMetadata.class, new NetworkMetadataDeserializer());
module.addDeserializer(PostContingencyResult.class, new PostContingencyResultDeserializer());
module.addDeserializer(LimitViolationsResult.class, new LimitViolationResultDeserializer());
module.addDeserializer(LimitViolation.class, new LimitViolationDeserializer());
module.addDeserializer(Contingency.class, new ContingencyDeserializer());
module.addDeserializer(ContingencyElement.class, new ContingencyElementDeserializer());
objectMapper.registerModule(module);
return objectMapper.readValue(is, SecurityAnalysisResult.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例3: initClient
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
private static void initClient() {
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
ObjectMapper objectMapper = JSONUtil.prettyMapper();
objectMapper.registerModule(
new SimpleModule()
.addDeserializer(JobDataFragment.class,
new JsonDeserializer<JobDataFragment>() {
@Override
public JobDataFragment deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
return jsonParser.readValueAs(DataPOJO.class);
}
}
)
);
provider.setMapper(objectMapper);
client = ClientBuilder.newBuilder().register(provider).register(MultiPartFeature.class).build();
WebTarget rootTarget = client.target("http://localhost:" + currentDremioDaemon.getWebServer().getPort());
currentApiV2 = rootTarget.path(API_LOCATION);
}
示例4: getAppStatusList
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
@JsonIgnore
public List<AppStatus> getAppStatusList() {
try {
ObjectMapper mapper = new ObjectMapper();
mapper.addMixIn(AppStatus.class, AppStatusMixin.class);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
resolver.addMapping(AppInstanceStatus.class, AppInstanceStatusImpl.class);
module.setAbstractTypes(resolver);
mapper.registerModule(module);
TypeReference<List<AppStatus>> typeRef = new TypeReference<List<AppStatus>>() {
};
if (this.platformStatus != null) {
return mapper.readValue(this.platformStatus, typeRef);
}
return new ArrayList<AppStatus>();
}
catch (Exception e) {
throw new IllegalArgumentException("Could not parse Skipper Platfrom Status JSON:" + platformStatus, e);
}
}
示例5: write
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
public static void write(SecurityAnalysisResult result, Writer writer) throws IOException {
Objects.requireNonNull(result);
Objects.requireNonNull(writer);
ObjectMapper objectMapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(SecurityAnalysisResult.class, new SecurityAnalysisResultSerializer());
module.addSerializer(NetworkMetadata.class, new NetworkMetadataSerializer());
module.addSerializer(PostContingencyResult.class, new PostContingencyResultSerializer());
module.addSerializer(LimitViolationsResult.class, new LimitViolationsResultSerializer());
module.addSerializer(LimitViolation.class, new LimitViolationSerializer());
module.addSerializer(ContingencyElement.class, new ContingencyElementSerializer());
objectMapper.registerModule(module);
ObjectWriter objectWriter = objectMapper.writerWithDefaultPrettyPrinter();
objectWriter.writeValue(writer, result);
}
示例6: write
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
private static void write(Contingency object, Path jsonFile) {
Objects.requireNonNull(object);
Objects.requireNonNull(jsonFile);
try (OutputStream os = Files.newOutputStream(jsonFile)) {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(ContingencyElement.class, new ContingencyElementSerializer());
mapper.registerModule(module);
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
writer.writeValue(os, object);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例7: createMapper
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
public static ObjectMapper createMapper(KBId kbId) {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(Fact.class, new FactSerializer(kbId));
module.addDeserializer(Fact.class, new FactDeSerializer(kbId));
module.addSerializer(PropertyEntity.class, new PropertySerializer(kbId));
module.addDeserializer(PropertyEntity.class, new PropertyDeserializer(kbId));
module.addSerializer(InstanceEntity.class, new InstanceSerializer(kbId));
module.addDeserializer(InstanceEntity.class, new InstanceDeserializer(kbId));
module.addSerializer(ClassEntity.class, new ClassSerializer(kbId));
mapper.registerModule(module);
return mapper;
}
示例8: createJacksonModule
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
/**
* Creates Crnk Jackson module with all required serializers.<br />
* Adds the {@link LinksInformationSerializer} if <code>serializeLinksAsObjects</code> is set to <code>true</code>.
*
* @param serializeLinksAsObjects flag which decides whether the {@link LinksInformationSerializer} should be added as
* additional serializer or not.
*
* @return {@link com.fasterxml.jackson.databind.Module} with custom serializers
*/
public static SimpleModule createJacksonModule(boolean serializeLinksAsObjects) {
SimpleModule simpleModule = new SimpleModule(JSON_API_JACKSON_MODULE_NAME,
new Version(1, 0, 0, null, null, null));
simpleModule.addSerializer(new ErrorDataSerializer());
simpleModule.addDeserializer(ErrorData.class, new ErrorDataDeserializer());
if (serializeLinksAsObjects) {
simpleModule.addSerializer(new LinksInformationSerializer());
}
return simpleModule;
}
示例9: createDefaultMapper
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
public static ObjectMapper createDefaultMapper() {
final ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_NULL);
mapper.configure(SerializationFeature.INDENT_OUTPUT, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
SimpleModule module = new SimpleModule();
module.addSerializer(Transaction.class, new TransactionSerializer());
module.addDeserializer(Transaction.class, new TransactionDeserializer());
module.addSerializer(Difficulty.class, new DifficultySerializer());
module.addDeserializer(Difficulty.class, new DifficultyDeserializer());
module.addSerializer(Block.class, new BlockSerializer());
module.addDeserializer(Block.class, new BlockDeserializer());
mapper.registerModule(module);
return mapper;
}
示例10: getEditorOptions
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
private ObjectExpression getEditorOptions(HtmlEditorConfiguration config)
{
final String options = config.getEditorOptions();
if( options == null || options.trim().length() == 0 )
{
return null;
}
try
{
final ObjectMapper jsonMapper = objectMapperService.createObjectMapper(LenientMapperExtension.NAME);
final SimpleModule module = new SimpleModule("equella", new Version(1, 0, 0, null));
module.addDeserializer(ObjectExpression.class, new ObjectExpressionDeserialiser());
jsonMapper.registerModule(module);
final ObjectExpression obj = jsonMapper.readValue(options, ObjectExpression.class);
return obj; // NOSONAR (kept local variable for readability)
}
catch( IOException io )
{
// Invalid editor options. Should never have happened.
LOGGER.error("Invalid HTML editor options", io);
return null;
}
}
示例11: extendMapper
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
@Override
public void extendMapper(ObjectMapper mapper)
{
SimpleModule restModule = new SimpleModule("RestModule", new Version(1, 0, 0, null));
// TODO this probably should be somewhere else, but it can't be in
// com.tle.core.jackson
// as that would make it dependent on equella i18n
restModule.addSerializer(new I18NSerializer());
mapper.registerModule(restModule);
mapper.registerModule(new JavaTypesModule());
mapper.registerModule(new RestStringsModule());
mapper.setSerializationInclusion(Include.NON_NULL);
// dev mode!
if( DebugSettings.isDebuggingMode() )
{
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
}
mapper.setDateFormat(new ISO8061DateFormatWithTZ());
}
示例12: BittrexExchange
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
public BittrexExchange(int retries, String apikey, String secret, HttpFactory httpFactory) throws IOException {
this.apikey = apikey;
this.secret = secret;
this.httpFactory = httpFactory;
this.retries = retries;
mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addDeserializer(ZonedDateTime.class, new DateTimeDeserializer());
mapper.registerModule(module);
updateExchangeStateType = mapper.getTypeFactory().constructType(UpdateExchangeState.class);
exchangeSummaryStateType = mapper.getTypeFactory().constructType(ExchangeSummaryState.class);
httpClient = httpFactory.createClient();
httpClientContext = httpFactory.createClientContext();
}
示例13: PhysicalPlanReader
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
public PhysicalPlanReader(DrillConfig config, ObjectMapper mapper, final DrillbitEndpoint endpoint,
final StoragePluginRegistry pluginRegistry) {
// Endpoint serializer/deserializer.
SimpleModule deserModule = new SimpleModule("PhysicalOperatorModule") //
.addSerializer(DrillbitEndpoint.class, new DrillbitEndpointSerDe.Se()) //
.addDeserializer(DrillbitEndpoint.class, new DrillbitEndpointSerDe.De()) //
.addSerializer(MajorType.class, new MajorTypeSerDe.Se())
.addDeserializer(MajorType.class, new MajorTypeSerDe.De());
mapper.registerModule(deserModule);
mapper.registerSubtypes(PhysicalOperatorUtil.getSubTypes(config));
InjectableValues injectables = new InjectableValues.Std() //
.addValue(StoragePluginRegistry.class, pluginRegistry) //
.addValue(DrillbitEndpoint.class, endpoint); //
this.mapper = mapper;
this.physicalPlanReader = mapper.reader(PhysicalPlan.class).with(injectables);
this.operatorReader = mapper.reader(PhysicalOperator.class).with(injectables);
this.logicalPlanReader = mapper.reader(LogicalPlan.class).with(injectables);
}
示例14: obj2NodeByFilter
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
/**
* 通过过滤器将对象转换成json
* @param serializer
* @param obj
* @return
* String
* @Author chenxiaojin
* @date 2014年11月25日
* @exception
* @version
*/
public static JsonNode obj2NodeByFilter(FilterPropsSerializer filterSerializer, Object obj)
{
ObjectMapper objMapper = new ObjectMapper();
SimpleModule simpleModule = new SimpleModule();
// 添加需要过滤的Class
for (Class<?> clz : filterSerializer.getSerializerClasses())
{
simpleModule.addSerializer(clz, filterSerializer);
}
// 注册模块
objMapper.registerModule(simpleModule);
objMapper.setDateFormat(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"));
try
{
String result = objMapper.writeValueAsString(obj);
return objMapper.readTree(result);
}
catch (IOException e)
{
return null;
}
}
示例15: customDecoder
import com.fasterxml.jackson.databind.module.SimpleModule; //导入依赖的package包/类
@Test
public void customDecoder() throws Exception {
JacksonDecoder decoder = new JacksonDecoder(
Arrays.<Module>asList(
new SimpleModule().addDeserializer(Zone.class, new ZoneDeserializer())));
List<Zone> zones = new LinkedList<Zone>();
zones.add(new Zone("DENOMINATOR.IO."));
zones.add(new Zone("DENOMINATOR.IO.", "ABCD"));
Response response = Response.builder()
.status(200)
.reason("OK")
.headers(Collections.<String, Collection<String>>emptyMap())
.body(zonesJson, UTF_8)
.build();
assertEquals(zones, decoder.decode(response, new TypeReference<List<Zone>>() {
}.getType()));
}