本文整理汇总了Java中com.fasterxml.jackson.datatype.jdk8.Jdk8Module类的典型用法代码示例。如果您正苦于以下问题:Java Jdk8Module类的具体用法?Java Jdk8Module怎么用?Java Jdk8Module使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Jdk8Module类属于com.fasterxml.jackson.datatype.jdk8包,在下文中一共展示了Jdk8Module类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createObjectMapper
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
public static ObjectMapper createObjectMapper() {
final YAMLFactory yamlFactory = new YAMLFactory()
.configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false)
.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)
.configure(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS, true)
.configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false);
ObjectMapper mapper = new ObjectMapper(yamlFactory)
.registerModule(new Jdk8Module())
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
.enable(SerializationFeature.INDENT_OUTPUT)
.disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
for (Step step : ServiceLoader.load(Step.class, YamlHelpers.class.getClassLoader())) {
mapper.registerSubtypes(new NamedType(step.getClass(), step.getKind()));
}
return mapper;
}
示例2: getObjectMapper
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
@Bean(name = "objectMapper")
public ObjectMapper getObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new GuavaModule());
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JodaModule());
mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
// borrowed from: http://jackson-users.ning.com/forum/topics/how-to-not-include-type-info-during-serialization-with
@Override
protected TypeResolverBuilder<?> _findTypeResolver(MapperConfig<?> config, Annotated ann, JavaType baseType) {
// Don't serialize JsonTypeInfo Property includes
if (ann.hasAnnotation(JsonTypeInfo.class)
&& ann.getAnnotation(JsonTypeInfo.class).include() == JsonTypeInfo.As.PROPERTY
&& SerializationConfig.class.isAssignableFrom(config.getClass())) {
return null;
}
return super._findTypeResolver(config, ann, baseType);
}
});
return mapper;
}
示例3: getApiService
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
/**
* Gets api service.
*
* @param enableHTTPLogging boolean to enable logging
* @return the bot api service
*/
public static TelegramBotApiService getApiService(Boolean enableHTTPLogging) {
if (ApiService == null) {
Logger.info("No instance of service yet. Building...");
ObjectMapper objectMapper = new ObjectMapper().registerModule(new Jdk8Module());
Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
.baseUrl("https://api.telegram.org/bot" + Token + "/")
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(JacksonConverterFactory.create(objectMapper));
if (enableHTTPLogging) {
Logger.info("Adding request logging...");
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(httpLoggingInterceptor);
retrofitBuilder.client(httpClient.build());
}
Retrofit retrofit = retrofitBuilder.build();
ApiService = retrofit.create(TelegramBotApiService.class);
}
Logger.debug("Returning ApiService instance.");
return ApiService;
}
示例4: configure
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
@Override
protected void configure() {
requireBinding(ServiceMetadata.class);
requireBinding(UriInfo.class);
bind(AvailabilityResource.class).to(AvailabilityResourceImpl.class);
bind(HealthResource.class).to(HealthResourceImpl.class);
bind(DependenciesResource.class).to(DependenciesResourceImpl.class);
bind(DiagnosticResource.class).to(DiagnosticResourceImpl.class);
bind(VersionResource.class).to(VersionResourceImpl.class);
bind(HealthChecker.class);
//This is to provide a default binding for HealthDependency,
// so that services with no HealthDependency bindings can start
Multibinder<HealthDependency> healthDependencyModuleBinder = Multibinder.newSetBinder(binder(),
HealthDependency.class);
Multibinder<Module> jacksonModuleBinder = Multibinder.newSetBinder(binder(), Module.class);
jacksonModuleBinder.addBinding().to(Jdk8Module.class);
jacksonModuleBinder.addBinding().to(JavaTimeModule.class);
install(MultibindingsScanner.asModule());
}
示例5: createObjectMapper
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
private static ObjectMapper createObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JavaTimeModule());
mapper.registerModule(new ParameterNamesModule());
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
return mapper;
}
示例6: testConvertFromJson
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
@Ignore("test-integration.json is outdated")
@Test
public void testConvertFromJson() throws Exception {
JsonNode json = new ObjectMapper().readTree(this.getClass().getResourceAsStream("test-integration.json"));
Integration integration = new ObjectMapper().registerModule(new Jdk8Module()).readValue(json.get("data").toString(), Integration.class);
ProjectGeneratorProperties generatorProperties = new ProjectGeneratorProperties(MAVEN_PROPERTIES);
generatorProperties.getTemplates().setOverridePath(this.basePath);
generatorProperties.getTemplates().getAdditionalResources().addAll(this.additionalResources);
Path runtimePath = generate(integration, generatorProperties);
assertFileContents(generatorProperties, runtimePath.resolve("src/main/java/io/syndesis/example/Application.java"), "test-Application.java");
assertFileContents(generatorProperties, runtimePath.resolve("src/main/resources/application.properties"), "test-pull-push-application.properties");
assertFileContents(generatorProperties, runtimePath.resolve("src/main/resources/syndesis.yml"), "test-pull-push-syndesis.yml");
assertFileContents(generatorProperties, runtimePath.resolve("pom.xml"), "test-pull-push-pom.xml");
}
示例7: deserializationEntityTypeTest
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
@Test
public void deserializationEntityTypeTest() throws IOException {
ObjectMapper objectMapper = new ObjectMapper().registerModule(new Jdk8Module());
Registration registration = objectMapper.readValue(jsonString, Registration.class);
assertEquals("abcdefg", registration.getId());
assertEquals(new URL("http://weather.example.com/ngsi"), registration.getCallback());
assertEquals("PT1M", registration.getDuration());
assertEquals(1, registration.getSubject().getEntities().size());
assertEquals("Bcn_Welt", registration.getSubject().getEntities().get(0).getId().get());
assertEquals("Room", registration.getSubject().getEntities().get(0).getType().get());
assertEquals(1, registration.getSubject().getAttributes().size());
assertEquals("temperature", registration.getSubject().getAttributes().get(0));
assertEquals(2, registration.getMetadata().size());
assertTrue(registration.getMetadata().containsKey("providingService"));
assertTrue(registration.getMetadata().containsKey("providingAuthority"));
}
示例8: deserializationEntityTest
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
@Test
public void deserializationEntityTest() throws IOException {
String jsonString = "{\n" +
" \"id\" : \"Bcn-Welt\",\n" +
" \"type\" : \"Room\",\n" +
" \"temperature\" : {\n" +
" \"value\" : 21.7\n" +
" },\n" +
" \"humidity\" : {\n" +
" \"value\" : 60\n" +
" }\n" +
"}";
ObjectMapper objectMapper = new ObjectMapper().registerModule(new Jdk8Module());
Entity entity = objectMapper.readValue(jsonString, Entity.class);
Attribute temp = entity.getAttributes().get("temperature");
assertEquals(0, temp.getMetadata().size());
}
示例9: before
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
@Before
public void before() throws Throwable {
mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
Protos.FrameworkInfo frameworkInfo = Protos.FrameworkInfo.newBuilder()
.setUser("")
.setName(RetzScheduler.FRAMEWORK_NAME)
.build();
InputStream in = Launcher.class.getResourceAsStream("/retz.properties");
Launcher.Configuration conf = new Launcher.Configuration(new ServerConfiguration(in));
Database.getInstance().init(conf.getServerConfig());
scheduler = new RetzScheduler(conf, frameworkInfo);
driver = new MesosSchedulerDummyDriver(scheduler, frameworkInfo, conf.getMesosMaster());
}
示例10: connect
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
static Retz connect(
URI uri,
Authenticator authenticator,
SSLSocketFactory socketFactory,
HostnameVerifier hostnameVerifier) {
String url = Objects.requireNonNull(uri, "uri cannot be null").toString();
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
return Feign.builder()
.client(new Client.Default(socketFactory, hostnameVerifier))
.logger(new Slf4jLogger())
.encoder(new JacksonEncoder(mapper))
.decoder(new JacksonDecoder(mapper))
.errorDecoder(new ErrorResponseDecoder(mapper))
.requestInterceptor(new AuthHeaderInterceptor(authenticator))
.target(Retz.class, url);
}
示例11: handle
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
@Override
public int handle(ClientCLIConfig fileConfig, boolean verbose) throws Throwable {
LOG.debug("Configuration: {}", fileConfig.toString());
try (Client webClient = Client.newBuilder(fileConfig.getUri())
.setAuthenticator(fileConfig.getAuthenticator())
.checkCert(!fileConfig.insecure())
.setVerboseLog(verbose)
.build()) {
Response res = webClient.getApp(appName);
if (res instanceof ErrorResponse) {
LOG.error(res.status());
} else if (res instanceof GetAppResponse) {
GetAppResponse getAppResponse = (GetAppResponse) res;
Application app = getAppResponse.application();
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
mapper.writeValue(System.out, app);
System.out.println();
return 0;
}
}
return -1;
}
示例12: longTest
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
@Test
public void longTest() throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
{ // Test GH#81 https://github.com/retz/retz/issues/81
String d = "{\"gid\":\"1000\",\"mode\":\"-rw-r--r--\",\"mtime\":1479109579.0,\"nlink\":1,\"path\":\"\\/var\\/lib\\/mesos\\/...\\/results\\/99.bin\",\"size\":5122002944,\"uid\":\"1000\"}";
DirEntry entry = mapper.readValue(d, DirEntry.class);
assertEquals(5122002944L, entry.size());
}
{
String f = "{\"data\": \"deadbeef\", \"offset\":999999999999}";
FileContent content = mapper.readValue(f, FileContent.class);
assertEquals(999999999999L, content.offset());
}
}
示例13: test1
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
@Test
public void test1() {
InstanceData_old data = InstanceDataGenerator_old.build();
System.out.println(data.toString());
try {
ObjectMapper mapper = new ObjectMapper().registerModule(new Jdk8Module());
SimpleModule module = new SimpleModule();
module.addKeyDeserializer(TypeVMJobClassKey.class, TypeVMJobClassKey.getDeserializer() );
mapper.registerModule(module);
String serialized = mapper.writeValueAsString(data);
System.out.println(serialized);
InstanceData_old data2 = mapper.readValue(serialized, InstanceData_old.class);
System.out.println(data2.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertTrue(data.getGamma() ==240);
}
示例14: beforeAll
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
@Before
public void beforeAll() throws Exception {
server = new TestingServer();
server.start();
Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
when(mockCapabilities.supportsNamedVips()).thenReturn(true);
taskFactory = new CassandraDaemonTask.Factory(mockCapabilities);
configurationFactory = new ConfigurationFactory<>(
MutableSchedulerConfiguration.class,
BaseValidator.newValidator(),
Jackson.newObjectMapper()
.registerModule(new GuavaModule())
.registerModule(new Jdk8Module()),
"dw");
connectString = server.getConnectString();
}
示例15: setupMapper
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; //导入依赖的package包/类
private static ObjectMapper setupMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
// objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
SimpleModule m = new SimpleModule();
objectMapper.registerModule(m);
objectMapper.registerModule(new JavaTimeModule());
objectMapper.registerModule(new Jdk8Module());
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
objectMapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
// objectMapper.disable(DeserializationFeature.);
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
// objectMapper.enableDefaultTyping();
objectMapper.addMixIn(Color.class, ColorMixInAnnotations.class);
return objectMapper;
}