本文整理汇总了Java中com.fasterxml.jackson.datatype.jsr310.JavaTimeModule类的典型用法代码示例。如果您正苦于以下问题:Java JavaTimeModule类的具体用法?Java JavaTimeModule怎么用?Java JavaTimeModule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaTimeModule类属于com.fasterxml.jackson.datatype.jsr310包,在下文中一共展示了JavaTimeModule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSystemEvent
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的package包/类
private String createSystemEvent(String tenant, String command) {
SystemEvent event = new SystemEvent();
event.setEventId(MDCUtil.getRid());
event.setEventType(command);
event.setTenantInfo(TenantContext.getCurrent());
event.setMessageSource(appName);
event.getData().put(Constants.EVENT_TENANT, tenant);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
try {
return mapper.writeValueAsString(event);
} catch (JsonProcessingException e) {
log.error("System Event mapping error", e);
throw new BusinessException("Event mapping error", e.getMessage());
}
}
示例2: start
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {
Json.mapper.registerModule(new JavaTimeModule());
FileSystem vertxFileSystem = vertx.fileSystem();
vertxFileSystem.readFile("swagger.json", readFile -> {
if (readFile.succeeded()) {
Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8")));
Router swaggerRouter = SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, vertx.eventBus(), new OperationIdServiceIdResolver());
deployVerticles(startFuture);
vertx.createHttpServer()
.requestHandler(swaggerRouter::accept)
.listen(8080);
startFuture.complete();
} else {
startFuture.fail(readFile.cause());
}
});
}
示例3: start
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {
Json.mapper.registerModule(new JavaTimeModule());
FileSystem vertxFileSystem = vertx.fileSystem();
vertxFileSystem.readFile("swagger.json", readFile -> {
if (readFile.succeeded()) {
Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8")));
SwaggerManager.getInstance().setSwagger(swagger);
Router swaggerRouter = SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, vertx.eventBus(), new OperationIdServiceIdResolver());
deployVerticles(startFuture);
vertx.createHttpServer()
.requestHandler(swaggerRouter::accept)
.listen(config().getInteger("http.port", 8080));
startFuture.complete();
} else {
startFuture.fail(readFile.cause());
}
});
}
示例4: IiifObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的package包/类
public IiifObjectMapper() {
this.checkJacksonVersion();
// Don't include null properties
this.setSerializationInclusion(Include.NON_NULL);
// Both are needed to add `@context` to the top-level object
this.disable(SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS);
this.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
// Some array fields are unwrapped during serialization if they have only one value
this.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
// Register the problem handler
this.addHandler(new ProblemHandler());
// Disable writing dates as timestamps
this.registerModule(new JavaTimeModule());
this.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
// Enable automatic detection of parameter names in @JsonCreators
this.registerModule(new ParameterNamesModule());
// Register the module
this.registerModule(new IiifModule());
}
示例5: convertObjectToJsonBytes
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的package包/类
/**
* Convert an object to JSON byte array.
*
* @param object
* the object to convert
* @return the JSON byte array
* @throws IOException
*/
public static byte[] convertObjectToJsonBytes(Object object)
throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
JavaTimeModule module = new JavaTimeModule();
module.addSerializer(OffsetDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(ZonedDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(LocalDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(Instant.class, JSR310DateTimeSerializer.INSTANCE);
module.addDeserializer(LocalDate.class, JSR310LocalDateDeserializer.INSTANCE);
mapper.registerModule(module);
return mapper.writeValueAsBytes(object);
}
示例6: configure
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的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());
}
示例7: createObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的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;
}
示例8: setUp
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
super.setUp();
client = new CrnkClient(getBaseUri().toString());
client.getObjectMapper().registerModule(new JavaTimeModule());
HttpAdapter httpAdapter = client.getHttpAdapter();
httpAdapter.setReceiveTimeout(10000, TimeUnit.SECONDS);
scheduleRepo = client.getRepositoryForInterface(ScheduleRepository.class);
approvalRepo = client.getRepositoryForType(ScheduleApprovalProcessInstance.class);
taskRepo = client.getRepositoryForType(ApproveTask.class);
approvalRelRepo = client.getRepositoryForType(Schedule.class, ScheduleApprovalProcessInstance.class);
formRepo = client.getRepositoryForType(ApproveForm.class);
}
示例9: getRegistryClient
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的package包/类
private RegistryEndpoints getRegistryClient(ImageRef imageRef) {
if (!proxyClients.containsKey(imageRef.getRegistryUrl())) {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
Client client = ClientBuilder.newClient()
.register(new JacksonJaxbJsonProvider(mapper, new Annotations[] {Annotations.JACKSON}))
.register(JacksonFeature.class);
String auth = config.getAuthFor(imageRef.getRegistryName());
if (auth != null) {
String[] credentials = new String(Base64.getDecoder().decode(auth), StandardCharsets.UTF_8).split(":");
client.register(HttpAuthenticationFeature.basicBuilder().credentials(credentials[0], credentials[1]));
}
WebTarget webTarget = client.target(imageRef.getRegistryUrl());
proxyClients.put(imageRef.getRegistryUrl(), WebResourceFactory.newResource(RegistryEndpoints.class, webTarget));
}
return proxyClients.get(imageRef.getRegistryUrl());
}
示例10: initializeMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的package包/类
private static ObjectMapper initializeMapper() {
return new ObjectMapper()
.registerModule(new JavaTimeModule())
.disable(MapperFeature.AUTO_DETECT_GETTERS)
.disable(MapperFeature.AUTO_DETECT_CREATORS)
.disable(MapperFeature.AUTO_DETECT_SETTERS)
.disable(MapperFeature.AUTO_DETECT_IS_GETTERS)
.disable(MapperFeature.AUTO_DETECT_FIELDS)
.disable(MapperFeature.DEFAULT_VIEW_INCLUSION)
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.NONE)
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
.enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS)
// serialization
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
.enable(SerializationFeature.USE_EQUALITY_FOR_OBJECT_ID)
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
// deserialization
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE);
}
示例11: updateUserStatusGood
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的package包/类
@Test
public void updateUserStatusGood() throws Exception {
final UserEntity entity = TestUtil.getUserEntity();
entity.setStatus(UserStatus.CLOSED);
final List<String> roles = new ArrayList<>();
roles.add(Role.ADMIN.getAuthority());
mapper.registerModule(new JavaTimeModule());
final byte[] content = mapper.writeValueAsBytes(new UserInfo(entity));
when(claims.get(JwtToken.KEY)).thenReturn(roles);
when(userService.updateUserStatus(anyString(), any(UserStatus.class))).thenReturn(entity);
mockMvc.perform(put(UsersController.PATH + "/" + entity.getId() + "/status/" + UserStatus.CLOSED).contentType(MediaType.APPLICATION_JSON).content(content))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.id", Matchers.is(equalTo(entity.getId()))))
.andExpect(jsonPath("$.status", Matchers.is(equalTo(UserStatus.CLOSED.toString()))));
}
示例12: testAddDatasetGoodAuthentication
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的package包/类
@Test
public void testAddDatasetGoodAuthentication() throws Exception {
final DataEntity dataEntity = TestUtil.getDataEntity();
dataEntity.setCategoryId(getDataCategoryEntity().getId());
mapper.registerModule(new JavaTimeModule());
final byte[] content = mapper.writeValueAsBytes(new DataInfo(dataEntity));
when(securityContext.getAuthentication()).thenReturn(authentication);
SecurityContextHolder.setContext(securityContext);
when(authentication.getPrincipal()).thenReturn(claims);
when(dataService.createDataset(any(DataInfo.class))).thenReturn(dataEntity);
mockMvc.perform(post(DataController.PATH)
.contentType(MediaType.APPLICATION_JSON)
.content(content))
.andExpect(status().isCreated())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("name", is(equalTo(dataEntity.getName()))))
.andExpect(jsonPath("description", is(equalTo(dataEntity.getDescription()))))
.andExpect(jsonPath("contributorId", is(equalTo(dataEntity.getContributorId()))))
.andExpect(jsonPath("accessibility", is(equalTo(dataEntity.getAccessibility().toString()))))
.andExpect(jsonPath("visibility", is(equalTo(dataEntity.getVisibility().toString()))));
}
示例13: testUpdateDatasetGoodAuthentication
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的package包/类
@Test
public void testUpdateDatasetGoodAuthentication() throws Exception {
final DataEntity dataEntity = TestUtil.getDataEntity();
dataEntity.setCategoryId(getDataCategoryEntity().getId());
mapper.registerModule(new JavaTimeModule());
final byte[] content = mapper.writeValueAsBytes(new DataInfo(dataEntity));
when(securityContext.getAuthentication()).thenReturn(authentication);
SecurityContextHolder.setContext(securityContext);
when(authentication.getPrincipal()).thenReturn(claims);
when(dataService.updateDataset(anyLong(), any(DataInfo.class), any(Claims.class))).thenReturn(dataEntity);
mockMvc.perform(put(DataController.PATH + "/1")
.contentType(MediaType.APPLICATION_JSON)
.content(content))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("name", is(equalTo(dataEntity.getName()))))
.andExpect(jsonPath("description", is(equalTo(dataEntity.getDescription()))))
.andExpect(jsonPath("contributorId", is(equalTo(dataEntity.getContributorId()))))
.andExpect(jsonPath("accessibility", is(equalTo(dataEntity.getAccessibility().toString()))))
.andExpect(jsonPath("visibility", is(equalTo(dataEntity.getVisibility().toString()))));
}
示例14: testSaveNewPublicUser
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的package包/类
@Test
public void testSaveNewPublicUser() throws Exception {
final DataPublicUserEntity dataPublicUserEntity = TestUtil.getDataPublicUserEntity();
mapper.registerModule(new JavaTimeModule());
final byte[] content = mapper.writeValueAsBytes(new DataPublicUserInfo(dataPublicUserEntity));
when(dataService.createPublicUser(any(DataPublicUserInfo.class))).thenReturn(dataPublicUserEntity);
mockMvc.perform(post(DataController.PATH + "/public/users")
.contentType(MediaType.APPLICATION_JSON)
.content(content))
.andExpect(status().isCreated())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("fullName", is(equalTo(dataPublicUserEntity.getFullName()))))
.andExpect(jsonPath("email", is(equalTo(dataPublicUserEntity.getEmail()))))
.andExpect(jsonPath("jobTitle", is(equalTo(dataPublicUserEntity.getJobTitle()))))
.andExpect(jsonPath("institution", is(equalTo(dataPublicUserEntity.getInstitution()))))
.andExpect(jsonPath("country", is(equalTo(dataPublicUserEntity.getCountry()))));
}
示例15: testRecipeDeserialization
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; //导入依赖的package包/类
@Test
public void testRecipeDeserialization() throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.configure(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS, false);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
Duration tagExpiry = Duration.ofSeconds(10);
LocationRecipe recipe = new LocationRecipe();
recipe.setName("RECIPE");
recipe.setType(RecipeType.LOCATION);
recipe.setTagExpiryDuration(tagExpiry);
String string = mapper.writeValueAsString(recipe);
Recipe recipeDeserialized = mapper.readValue(string, Recipe.class);
Assert.assertEquals("RECIPE", recipeDeserialized.getName());
Assert.assertEquals(RecipeType.LOCATION, recipeDeserialized.getType());
Assert.assertEquals(tagExpiry, recipeDeserialized.getTagExpiryDuration());
}