Java Code Examples for org.springframework.hateoas.hal.Jackson2HalModule

The following examples show how to use org.springframework.hateoas.hal.Jackson2HalModule. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private AbstractSimulatedDevice createDdiDevice(final String id, final String tenant, final int pollDelaySec,
        final URL baseEndpoint, final String gatewayToken) {

    final ObjectMapper mapper = new ObjectMapper()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .registerModule(new Jackson2HalModule());

    final RootControllerResourceClient controllerResource = Feign.builder()
            .requestInterceptor(new GatewayTokenInterceptor(gatewayToken))
            .contract(new IgnoreMultipleConsumersProducersSpringMvcContract()).logLevel(Level.HEADERS)
            .decoder(new ResponseEntityDecoder(new JacksonDecoder(mapper))).encoder(new JacksonEncoder())
            .logger(new Slf4jLogger()).decode404()
            .target(RootControllerResourceClient.class, baseEndpoint.toString());

    return new DDISimulatedDevice(id, tenant, pollDelaySec, controllerResource, deviceUpdater, gatewayToken);
}
 
Example 2
Source Project: moserp   Source File: ObjectMapperCustomizer.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source Project: myfeed   Source File: MyfeedAutoConfig.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
private MappingJackson2HttpMessageConverter getHalMessageConverter() {
	ObjectMapper objectMapper = new ObjectMapper();
	objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	objectMapper.registerModule(new Jackson2HalModule());
	MappingJackson2HttpMessageConverter halConverter = new TypeConstrainedMappingJackson2HttpMessageConverter(
			ResourceSupport.class);
	halConverter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
	halConverter.setObjectMapper(objectMapper);
	return halConverter;
}
 
Example 5
private MappingJackson2HttpMessageConverter getHalMessageConverter() {
	ObjectMapper objectMapper = new ObjectMapper();
	objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	objectMapper.registerModule(new Jackson2HalModule());
	MappingJackson2HttpMessageConverter halConverter = new TypeConstrainedMappingJackson2HttpMessageConverter(
			ResourceSupport.class);
	halConverter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
	halConverter.setObjectMapper(objectMapper);
	return halConverter;
}
 
Example 6
Source Project: microservice-consul   Source File: CustomerClient.java    License: Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 7
Source Project: microservice-consul   Source File: CatalogClient.java    License: Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 8
Source Project: microservice-consul   Source File: CatalogClient.java    License: Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 9
Source Project: microservice-consul   Source File: CustomerClient.java    License: Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 10
Source Project: spring-cloud-in-action   Source File: ReservationService.java    License: MIT License 5 votes vote down vote up
@Bean
public Decoder feignDecoder() {
  ObjectMapper objectMapper = new ObjectMapper()
      .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
      .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
      .registerModule(new Jackson2HalModule());

  MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter();
  jacksonConverter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
  jacksonConverter.setObjectMapper(objectMapper);

  ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(jacksonConverter);
  return new ResponseEntityDecoder(new SpringDecoder(objectFactory));
}
 
Example 11
Source Project: hawkbit-examples   Source File: Application.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private static MgmtSoftwareModuleClientResource uploadSoftwareModule(
        final ClientConfigurationProperties configuration) {
    final ObjectMapper mapper = new ObjectMapper()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .registerModule(new Jackson2HalModule());
    return Feign.builder().contract(new IgnoreMultipleConsumersProducersSpringMvcContract()).decode404()
            .requestInterceptor(
                    new BasicAuthRequestInterceptor(configuration.getUsername(), configuration.getPassword()))
            .logger(new Slf4jLogger()).encoder(new FeignMultipartEncoder())
            .decoder(new ResponseEntityDecoder(new JacksonDecoder(mapper)))
            .target(MgmtSoftwareModuleClientResource.class, configuration.getUrl());
}
 
Example 12
Source Project: orders   Source File: AsyncGetService.java    License: Apache License 2.0 5 votes vote down vote up
@Autowired
public AsyncGetService(RestProxyTemplate restProxyTemplate) {
    this.restProxyTemplate = restProxyTemplate;
    this.halTemplate = new RestTemplate(restProxyTemplate.getRestTemplate().getRequestFactory());

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.registerModule(new Jackson2HalModule());
    MappingJackson2HttpMessageConverter halConverter = new MappingJackson2HttpMessageConverter();
    halConverter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
    halConverter.setObjectMapper(objectMapper);
    halTemplate.setMessageConverters(Collections.singletonList(halConverter));
}
 
Example 13
@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;
}
 
Example 14
Source Project: moserp   Source File: HalRestTemplate.java    License: Apache License 2.0 5 votes vote down vote up
public HalRestTemplate() {
    ObjectMapper halObjectMapper = new ObjectMapper();
    halObjectMapper.registerModule(new Jackson2HalModule());
    halObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    MappingJackson2HttpMessageConverter halConverter = new MappingJackson2HttpMessageConverter();
    halConverter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
    halConverter.setObjectMapper(halObjectMapper);
    getMessageConverters().add(halConverter);
}
 
Example 15
Source Project: moserp   Source File: ObjectMapperBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public ObjectMapper build() {
    ObjectMapper mapper = new ObjectMapper();
    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;
}
 
Example 16
Source Project: moserp   Source File: ObjectMapperBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public ObjectMapper build() {
    ObjectMapper mapper = new ObjectMapper();
    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;
}
 
Example 17
@Bean
public Module Jackson2HalModule() {
	return new Jackson2HalModule();
}