本文整理汇总了Java中org.springframework.hateoas.hal.Jackson2HalModule类的典型用法代码示例。如果您正苦于以下问题:Java Jackson2HalModule类的具体用法?Java Jackson2HalModule怎么用?Java Jackson2HalModule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Jackson2HalModule类属于org.springframework.hateoas.hal包,在下文中一共展示了Jackson2HalModule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRestTemplate
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
protected RestTemplate getRestTemplate() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new Jackson2HalModule());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
converter.setObjectMapper(mapper);
return new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter));
}
示例2: setup
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
@Before
public void setup() {
typeResolver = mock(TypeResolver.class);
configuration = Configuration.build();
instantiator = mock(HandlerInstantiator.class);
doReturn(new ResourceDeserializer(Object.class, typeResolver, configuration))
.when(instantiator).deserializerInstance(any(DeserializationConfig.class),
any(Annotated.class), eq(ResourceDeserializer.class));
mapper = new ObjectMapper();
mapper.setHandlerInstantiator(instantiator);
mapper.registerModule(new Jackson2HalModule());
mapper.registerModule(new TestModule());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
示例3: postProcessAfterInitialization
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (!(bean instanceof ObjectMapper)) {
return bean;
}
ObjectMapper mapper = (ObjectMapper) bean;
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
mapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
registerQuantitySerializer(mapper);
mapper.registerModules(new MoneyModule(), new JavaTimeModule(), new Jackson2HalModule());
return mapper;
}
示例4: getHttpMessageConverters
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
private List<HttpMessageConverter<?>> getHttpMessageConverters() {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jackson2HalModule());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(mapper);
converter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
converters.add(converter);
return converters;
}
示例5: init
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
public void init() {
HATEOAS_MEDIA_TYPE = MediaType.parseMediaType("application/hal+json");
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new Jackson2HalModule());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(Arrays.asList(HATEOAS_MEDIA_TYPE));
converter.setObjectMapper(mapper);
hateoasRestTemplate = new RestTemplate(Arrays.<HttpMessageConverter<?>> asList(converter));
hateoasRestTemplate.setErrorHandler(new DefaultResponseErrorHandler());
//restTemplate = new RestTemplate(Arrays.<HttpMessageConverter<?>> asList(new MappingJackson2HttpMessageConverter()));
//restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
}
示例6: postProcessBeforeInitialization
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
@Override
public Object postProcessBeforeInitialization(Object bean, String s) {
if (bean instanceof RequestMappingHandlerAdapter) {
((RequestMappingHandlerAdapter) bean).getMessageConverters().stream()
.filter(converter -> converter instanceof MappingJackson2HttpMessageConverter)
.forEach(converter -> {
MappingJackson2HttpMessageConverter halConverterCandidate = (MappingJackson2HttpMessageConverter) converter;
ObjectMapper objectMapper = halConverterCandidate.getObjectMapper();
if (Jackson2HalModule.isAlreadyRegisteredIn(objectMapper)) {
List<MediaType> vendorSpecificTypes = new ArrayList<>(halConverterCandidate.getSupportedMediaTypes());
vendorSpecificTypes.add(V1MediaType.V1_HAL_DOCUMENT_COLLECTION_MEDIA_TYPE);
vendorSpecificTypes.add(V1MediaType.V1_HAL_DOCUMENT_MEDIA_TYPE);
vendorSpecificTypes.add(V1MediaType.V1_HAL_FOLDER_MEDIA_TYPE);
vendorSpecificTypes.add(V1MediaType.V1_HAL_DOCUMENT_CONTENT_VERSION_MEDIA_TYPE);
vendorSpecificTypes.add(V1MediaType.V1_HAL_AUDIT_ENTRY_MEDIA_TYPE);
vendorSpecificTypes.add(V1MediaType.V1_HAL_DOCUMENT_AND_METADATA_COLLECTION_MEDIA_TYPE);
vendorSpecificTypes.add(V1MediaType.V1_DOCUMENT_COLLECTION_MEDIA_TYPE);
vendorSpecificTypes.add(V1MediaType.V1_DOCUMENT_MEDIA_TYPE);
vendorSpecificTypes.add(V1MediaType.V1_FOLDER_MEDIA_TYPE);
vendorSpecificTypes.add(V1MediaType.V1_DOCUMENT_CONTENT_VERSION_MEDIA_TYPE);
vendorSpecificTypes.add(V1MediaType.V1_AUDIT_ENTRY_MEDIA_TYPE);
((MappingJackson2HttpMessageConverter) converter).setSupportedMediaTypes(vendorSpecificTypes);
}
});
}
return bean;
}
示例7: mappingJackson2HttpMessageConverter
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
jsonConverter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
objectMapper.registerModule(new Jackson2HalModule());
jsonConverter.setObjectMapper(objectMapper);
return jsonConverter;
}
示例8: postConstructConfiguration
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
@PostConstruct
public void postConstructConfiguration() {
// Expose ids for the domain entities having repositories
logger.info("Exposing IDs on repositories...");
restConfiguration.config().exposeIdsFor(User.class);
restConfiguration.config().exposeIdsFor(Product.class);
// Register the ObjectMapper module for properly rendering HATEOAS REST repositories
logger.info("Registering Jackson2HalModule...");
restConfiguration.objectMapper().registerModule(new Jackson2HalModule());
}
示例9: postConstructConfiguration
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
@PostConstruct
public void postConstructConfiguration() {
// Expose ids for the domain entities having repositories
logger.info("Exposing IDs on repositories...");
restConfiguration.config().exposeIdsFor(User.class);
restConfiguration.config().exposeIdsFor(Product.class);
restConfiguration.config().exposeIdsFor(Rating.class);
// Register the ObjectMapper module for properly rendering HATEOAS REST repositories
logger.info("Registering Jackson2HalModule...");
restConfiguration.objectMapper().registerModule(new Jackson2HalModule());
}
示例10: jsonRedisSerializer
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
private Jackson2JsonRedisSerializer jsonRedisSerializer(JavaType javaType)
{
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(javaType);
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping();
mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY);
mapper.findAndRegisterModules();
mapper.registerModule(new Jackson2HalModule());
mapper.setHandlerInstantiator(new Jackson2HalModule.HalHandlerInstantiator(new DefaultRelProvider(), null, null));
jackson2JsonRedisSerializer.setObjectMapper(mapper);
return jackson2JsonRedisSerializer;
}
示例11: getIncidentsPaged
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
@Override
@JsonSerialize(using = Jackson2HalModule.HalResourcesSerializer.class)
@JsonDeserialize(using = Jackson2HalModule.HalResourcesDeserializer.class)
public PagedIncidents getIncidentsPaged(int pagenum,int pagesize) {
LOG.info("Performing get {} web service", applicationProperties.getIncidentApiUrl() +"/incidents");
final String restUri = applicationProperties.getIncidentApiUrl() +"/incidents?page="+pagenum+"&size="+pagesize;
ResponseEntity<PagedResources<IncidentBean>> response = restTemplate.exchange(restUri, HttpMethod.GET, null,
new ParameterizedTypeReference<PagedResources<IncidentBean>>() {});
// LOG.info("Total Incidents {}", response.getBody().size());
PagedResources<IncidentBean> beanResources = response.getBody();
PagedIncidents incidents = new PagedIncidents(beanResources,pagenum);
return incidents;
}
示例12: getRestTemplate
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
protected RestTemplate getRestTemplate() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
false);
mapper.registerModule(new Jackson2HalModule());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
converter.setObjectMapper(mapper);
return new RestTemplate(
Collections.<HttpMessageConverter<?>> singletonList(converter));
}
示例13: restTemplate
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
@Bean
public RestTemplate restTemplate() {
final ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jackson2HalModule());
final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
converter.setObjectMapper(mapper);
return new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter));
}
示例14: getHalMessageConverter
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
private HttpMessageConverter getHalMessageConverter() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.registerModule(new Jackson2HalModule());
MappingJackson2HttpMessageConverter halConverter = new TypeConstrainedMappingJackson2HttpMessageConverter(Resource.class);
halConverter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
halConverter.setObjectMapper(objectMapper);
return halConverter;
}
示例15: create
import org.springframework.hateoas.hal.Jackson2HalModule; //导入依赖的package包/类
@Override
public ObjectMapper create(HandlerInstantiator instantiator) {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new Jackson2HalModule());
mapper.registerModule(new JacksonClientModule());
mapper.setHandlerInstantiator(instantiator);
return mapper;
}