Java Code Examples for com.fasterxml.jackson.datatype.jdk8.Jdk8Module

The following examples show how to use com.fasterxml.jackson.datatype.jdk8.Jdk8Module. 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
Source Project: Singularity   Source File: SingularityClientModule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
  ObjectMapper objectMapper = JavaUtils.newObjectMapper();
  objectMapper.registerModule(new GuavaModule());
  objectMapper.registerModule(new Jdk8Module());

  HttpClient httpClient = new NingHttpClient(
    httpConfig.orElse(HttpConfig.newBuilder().setObjectMapper(objectMapper).build())
  );
  bind(HttpClient.class)
    .annotatedWith(Names.named(HTTP_CLIENT_NAME))
    .toInstance(httpClient);

  bind(SingularityClient.class)
    .toProvider(SingularityClientProvider.class)
    .in(Scopes.SINGLETON);

  if (hosts != null) {
    bindHosts(binder()).toInstance(hosts);
  }
}
 
Example 2
Source Project: FreeBuilder   Source File: PrimitiveOptionalPropertyTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJacksonInteroperability() {
  behaviorTester
      .with(new Processor(features))
      .with(datatype)
      .with(testBuilder()
          .addLine("DataType value = new DataType.Builder().%s(%s).build();",
              convention.set("item"), optional.example(0))
          .addLine("%1$s mapper = new %1$s()", ObjectMapper.class)
          .addLine("    .registerModule(new %s());", Jdk8Module.class)
          .addLine("String json = mapper.writeValueAsString(value);")
          .addLine("assertEquals(\"{\\\"item\\\":%s}\", json);", optional.example(0))
          .addLine("DataType clone = mapper.readValue(json, DataType.class);")
          .addLine("assertEquals(%s.of(%s), clone.%s);",
              optional.type, optional.example(0), convention.get("item"))
          .build())
      .runTest();
}
 
Example 3
Source Project: botbuilder-java   Source File: JacksonAdapter.java    License: MIT License 6 votes vote down vote up
/**
 * Initializes an instance of JacksonMapperAdapter with default configurations
 * applied to the object mapper.
 *
 * @param mapper the object mapper to use.
 */
private static ObjectMapper initializeObjectMapper(ObjectMapper mapper) {
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
            .configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, true)
            .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
            .configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true)
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .registerModule(new Jdk8Module())
            .registerModule(new JavaTimeModule())
            .registerModule(new ParameterNamesModule())
            .registerModule(ByteArraySerializer.getModule())
            .registerModule(Base64UrlSerializer.getModule())
            .registerModule(HeadersSerializer.getModule());
    mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));
    return mapper;
}
 
Example 4
Source Project: heroic   Source File: HeroicMappers.java    License: Apache License 2.0 6 votes vote down vote up
public static ObjectMapper json(final QueryParser parser) {
    final ObjectMapper mapper = new ObjectMapper();

    mapper.addMixIn(AggregationInstance.class, TypeNameMixin.class);
    mapper.addMixIn(Aggregation.class, TypeNameMixin.class);

    mapper.registerModule(new Jdk8Module().configureAbsentsAsNulls(true));
    mapper.registerModule(commonSerializers());
    mapper.registerModule(jsonSerializers());
    mapper.registerModule(new KotlinModule());

    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    mapper.registerModule(FilterRegistry.registry().module(parser));

    return mapper;
}
 
Example 5
Source Project: jersey-jwt-springsecurity   Source File: ObjectMapperProvider.java    License: MIT License 6 votes vote down vote up
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;
    }
 
Example 6
Source Project: taskana   Source File: RestHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return a REST template which is capable of dealing with responses in HAL format.
 *
 * @return RestTemplate
 */
private static RestTemplate getRestTemplate() {
  ObjectMapper mapper = new ObjectMapper();
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
  mapper.registerModule(new Jackson2HalModule());
  mapper
      .registerModule(new ParameterNamesModule())
      .registerModule(new Jdk8Module())
      .registerModule(new JavaTimeModule());

  MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
  converter.setSupportedMediaTypes(Collections.singletonList(MediaTypes.HAL_JSON));
  converter.setObjectMapper(mapper);

  RestTemplate template = new RestTemplate();
  // important to add first to ensure priority
  template.getMessageConverters().add(0, converter);
  return template;
}
 
Example 7
Source Project: quilt   Source File: StreamPacketFixturesTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Loads a list of tests based on the json-encoded test vector files.
 */
@Parameters(name = "Test Vector {index}: {0}")
public static Collection<StreamTestFixture> testVectorData() throws Exception {

  final ObjectMapper objectMapper = new ObjectMapper();
  objectMapper.registerModule(new Jdk8Module());
  objectMapper.registerModule(new GuavaModule());
  objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

  Properties properties = readProperties();
  String fileName = (String) properties.get("stream.packetFixtures.fileName");

  Path path = Paths.get(StreamPacketFixturesTest.class.getClassLoader().getResource(fileName).toURI());

  Stream<String> lines = Files.lines(path);
  String data = lines.collect(Collectors.joining("\n"));
  lines.close();

  List<StreamTestFixture> vectors = objectMapper.readValue(data, new TypeReference<List<StreamTestFixture>>() {});

  return vectors;
}
 
Example 8
Source Project: vavr-jackson   Source File: Issue141Test.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void itShouldSerializeJavaOptionalYearMonthAsString() throws IOException {
    // Given an instance with java.util.Optional
    MyJavaOptionalClass obj = new MyJavaOptionalClass();
    obj.operatingMonth = Optional.of(YearMonth.of(2019, 12));

    // When serializing the instance using object mapper
    // with Java Time Module and JDK8 Module
    ObjectMapper objectMapper = mapper();
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.registerModule(new Jdk8Module());
    String json = objectMapper.writeValueAsString(obj);

    // Then serialization is successful
    Assertions.assertEquals("{\"operatingMonth\":\"12-2019\"}", json);

    // And deserialization is successful
    MyJavaOptionalClass obj2 = objectMapper.readValue(json, MyJavaOptionalClass.class);
    Assertions.assertEquals(Optional.of(YearMonth.of(2019, 12)), obj2.operatingMonth);
}
 
Example 9
Source Project: jersey-jwt   Source File: ObjectMapperProvider.java    License: MIT License 6 votes vote down vote up
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;
    }
 
Example 10
Source Project: titus-control-plane   Source File: ObjectMappers.java    License: Apache License 2.0 6 votes vote down vote up
private static ObjectMapper createAppScalePolicyMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.registerModule(new Jdk8Module());
    objectMapper.addMixIn(AlarmConfiguration.class, AlarmConfigurationMixIn.class);
    objectMapper.addMixIn(StepAdjustment.class, StepAdjustmentMixIn.class);
    objectMapper.addMixIn(StepScalingPolicyConfiguration.class, StepScalingPolicyConfigurationMixIn.class);
    objectMapper.addMixIn(PolicyConfiguration.class, PolicyConfigurationMixIn.class);
    objectMapper.addMixIn(AutoScalingPolicy.class, AutoScalingPolicyMixIn.class);
    objectMapper.addMixIn(TargetTrackingPolicy.class, TargetTrackingPolicyMixin.class);
    objectMapper.addMixIn(PredefinedMetricSpecification.class, PredefinedMetricSpecificationMixin.class);
    objectMapper.addMixIn(CustomizedMetricSpecification.class, CustomizedMetricSpecificationMixin.class);
    objectMapper.addMixIn(MetricDimension.class, MetricDimensionMixin.class);

    return objectMapper;
}
 
Example 11
@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();
}
 
Example 12
Source Project: Singularity   Source File: JavaUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static ObjectMapper newObjectMapper() {
  final ObjectMapper mapper = new ObjectMapper();
  mapper.setSerializationInclusion(Include.NON_ABSENT);
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  mapper.registerModule(new GuavaModule());
  mapper.registerModule(new ProtobufModule());
  mapper.registerModule(new Jdk8Module());
  return mapper;
}
 
Example 13
Source Project: besu   Source File: JsonBlockImporter.java    License: Apache License 2.0 5 votes vote down vote up
public JsonBlockImporter(final BesuController controller) {
  this.controller = controller;
  mapper = new ObjectMapper();
  // Jdk8Module allows us to easily parse {@code Optional} values from json
  mapper.registerModule(new Jdk8Module());
  // Ignore casing of properties
  mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
}
 
Example 14
Source Project: mantis   Source File: MetricsServer.java    License: Apache License 2.0 5 votes vote down vote up
public MetricsServer(int port, long publishRateInSeconds, Map<String, String> tags) {
    this.port = port;
    this.publishRateInSeconds = publishRateInSeconds;
    this.tags = tags;
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.registerModule(new Jdk8Module());
}
 
Example 15
Source Project: data-prep   Source File: PreparationExportStrategyTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    // Given
    mapper.registerModule(new Jdk8Module());
    injectObjectMapper(strategy);

    when(formatRegistrationService.getByName(eq("JSON"))).thenReturn(new JsonFormat());

    DataSet dataSet = new DataSet();
    final DataSetMetadata dataSetMetadata = new DataSetMetadata("ds-1234", "", "", 0L, 0L, new RowMetadata(), "");
    final DataSetContent content = new DataSetContent();
    dataSetMetadata.setContent(content);
    dataSet.setMetadata(dataSetMetadata);
    dataSet.setRecords(Stream.empty());

    when(datasetClient.getDataSet(anyString())).thenReturn(dataSet);
    //when(datasetClient.getDataSetMetadata(anyString())).thenReturn(dataSetMetadata);

    final PreparationGetActions preparationGetActions = mock(PreparationGetActions.class);
    when(preparationGetActions.execute()).thenReturn(Collections.emptyList());
    when(applicationContext.getBean(eq(PreparationGetActions.class), eq("prep-1234"), anyString()))
            .thenReturn(preparationGetActions);

    final TransformationCacheKey cacheKey = mock(TransformationCacheKey.class);
    when(cacheKey.getKey()).thenReturn("cache-1234");
    when(cacheKeyGenerator.generateContentKey(anyString(), anyString(), anyString(), anyString(), any(), any(),
            anyString())).thenReturn(cacheKey);

    final ExecutableTransformer executableTransformer = mock(ExecutableTransformer.class);
    reset(transformer);
    when(transformer.buildExecutable(any(), any())).thenReturn(executableTransformer);
    when(factory.get(any())).thenReturn(transformer);

    when(contentCache.put(any(), any())).thenReturn(new NullOutputStream());
}
 
Example 16
/**
 * Method to configure the Jackson JSON mappers
 * 
 * @return jakcson {@link ObjectMapper} for JSON objects
 */
private ObjectMapper configureMapper() {
    return new ObjectMapper()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .registerModule(new Jdk8Module())
            .registerModule(new JavaTimeModule());
}
 
Example 17
Source Project: keywhiz   Source File: CliModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides public ObjectMapper generalMapper() {
  /**
   * Customizes ObjectMapper for common settings.
   *
   * @param objectMapper to be customized
   * @return customized input factory
   */
  ObjectMapper objectMapper = Jackson.newObjectMapper();
  objectMapper.registerModule(new Jdk8Module());
  objectMapper.registerModules(new JavaTimeModule());
  objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  return objectMapper;
}
 
Example 18
Source Project: codeway_service   Source File: RedisConfig.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 配置自定义Json序列化器 jackson2
 *
 * @param redisConnectionFactory :redis连接工厂
 * @return :RedisTemplate
 */
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
    RedisTemplate<String, Object> template = new RedisTemplate<>();
    template.setConnectionFactory(redisConnectionFactory);
    // 使用jackson2序列化
    Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);

    ObjectMapper mapper = new ObjectMapper();
    mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    mapper.registerModule(new Jdk8Module())
            .registerModule(new JavaTimeModule());
    jackson2JsonRedisSerializer.setObjectMapper(mapper);
    StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();

    // key采用String的序列化方式
    template.setKeySerializer(stringRedisSerializer);
    // hash的key也采用String的序列化方式
    template.setHashKeySerializer(stringRedisSerializer);
    // value序列化方式采用jackson
    template.setValueSerializer(jackson2JsonRedisSerializer);

    // hash的value序列化方式采用jackson
    template.setHashValueSerializer(jackson2JsonRedisSerializer);
    template.afterPropertiesSet();


    // 设置默认使用Jackson序列化
    template.setDefaultSerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));
    return template;
}
 
Example 19
Source Project: dcos-commons   Source File: SerializationUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new {@link ObjectMapper} with default modules against the provided factory.
 *
 * @param mapper the instance to register default modules with
 */
public static ObjectMapper registerDefaultModules(ObjectMapper mapper) {
  // enable support for ...
  return mapper.registerModules(
      // Optional<>s
      new Jdk8Module(),
      // Protobuf objects
      new ProtobufModule());
}
 
Example 20
Source Project: heroic   Source File: HeroicMappers.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Setup the ObjectMapper used to deserialize configuration files.
 *
 * @return
 */
public static ObjectMapper config() {
    final ObjectMapper m = new ObjectMapper(new YAMLFactory());

    m.addMixIn(ClusterDiscoveryModule.class, TypeNameMixin.class);
    m.addMixIn(RpcProtocolModule.class, TypeNameMixin.class);
    m.addMixIn(ConsumerModule.Builder.class, TypeNameMixin.class);
    m.addMixIn(MetadataModule.class, TypeNameMixin.class);
    m.addMixIn(SuggestModule.class, TypeNameMixin.class);
    m.addMixIn(MetricModule.class, TypeNameMixin.class);
    m.addMixIn(MetricGeneratorModule.class, TypeNameMixin.class);
    m.addMixIn(MetadataGenerator.class, TypeNameMixin.class);
    m.addMixIn(AnalyticsModule.Builder.class, TypeNameMixin.class);
    m.addMixIn(StatisticsModule.class, TypeNameMixin.class);
    m.addMixIn(QueryLoggingModule.class, TypeNameMixin.class);
    m.addMixIn(CacheModule.Builder.class, TypeNameMixin.class);
    m.addMixIn(RequestCondition.class, TypeNameMixin.class);
    m.addMixIn(ConditionalFeatures.class, TypeNameMixin.class);
    m.addMixIn(UsageTrackingModule.Builder.class, TypeNameMixin.class);

    m.registerModule(commonSerializers());

    /* support Optional */
    m.registerModule(new Jdk8Module());

    // Support Kotlin data classes
    m.registerModule(new KotlinModule());

    return m;
}
 
Example 21
Source Project: quarkus-quickstarts   Source File: PersonResourceTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void initAll() {
    RestAssured.defaultParser = Parser.JSON;
    RestAssured.config
            .logConfig((logConfig().enableLoggingOfRequestAndResponseIfValidationFails()))
            .objectMapperConfig(new ObjectMapperConfig().jackson2ObjectMapperFactory((type, s) -> new ObjectMapper()
                    .registerModule(new Jdk8Module())
                    .registerModule(new JavaTimeModule())
                    .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)));
}
 
Example 22
Source Project: dropwizard-java8   Source File: Java8Bundle.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(final Bootstrap<?> bootstrap) {
    bootstrap.getObjectMapper().registerModules(new Jdk8Module());
    bootstrap.getObjectMapper().registerModules(new JavaTimeModule());

    final ValidatorFactory validatorFactory = Validators.newConfiguration()
            .addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
            .buildValidatorFactory();
    bootstrap.setValidatorFactory(validatorFactory);
}
 
Example 23
Source Project: heroic   Source File: QueryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    mapper = new ObjectMapper();
    mapper.addMixIn(Aggregation.class, TypeNameMixin.class);
    mapper.registerModule(new Jdk8Module());
    mapper.registerSubtypes(new NamedType(Group.class, Group.NAME));
    mapper.registerSubtypes(new NamedType(Empty.class, Empty.NAME));
}
 
Example 24
Source Project: immutables   Source File: BackendResource.java    License: Apache License 2.0 5 votes vote down vote up
BackendResource(MongoDatabase database) {
  this.database = Objects.requireNonNull(database, "database");
  final ObjectMapper mapper = new ObjectMapper()
          .registerModule(new BsonModule())
          .registerModule(new GuavaModule())
          .registerModule(new Jdk8Module())
          .registerModule(new IdAnnotationModule());

  this.registry = JacksonCodecs.registryFromMapper(mapper);
  this.resolver = new LazyResolver();
  this.backend = new MongoBackend(MongoSetup.of(this.resolver));
}
 
Example 25
Source Project: keywhiz   Source File: JsonHelpers.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Customized ObjectMapper for common settings.
 *
 * @return customized object mapper
 */
private static ObjectMapper customizeObjectMapper() {
  ObjectMapper mapper = new ObjectMapper();
  mapper.registerModule(new Jdk8Module());
  mapper.registerModule(new GuavaModule());
  mapper.registerModule(new GuavaExtrasModule());
  mapper.registerModule(new FuzzyEnumModule());
  mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
  mapper.setSubtypeResolver(new DiscoverableSubtypeResolver());
  mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  return mapper;
}
 
Example 26
Source Project: symbol-sdk-java   Source File: JsonHelperJackson2.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("squid:CallToDeprecatedMethod")
public static ObjectMapper configureMapper(ObjectMapper objectMapper) {
    objectMapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS,
        false); //I cannot annotate the generated classes like the alternative recommended by jackson
    objectMapper.configure(DeserializationFeature.USE_LONG_FOR_INTS, true);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    SimpleModule module = new SimpleModule();
    module.addSerializer(BigInteger.class, new BigIntegerSerializer());
    objectMapper.registerModule(module);
    objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
    objectMapper.setSerializationInclusion(Include.NON_EMPTY);
    objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
    objectMapper.registerModule(new Jdk8Module());
    return objectMapper;
}
 
Example 27
@BeforeEach
void setup() {
    this.objectMapper = new ObjectMapper()
        .registerModule(new Jdk8Module())
        .setSerializationInclusion(JsonInclude.Include.NON_ABSENT);

    this.converter = new DeletedMessageWithStorageInformationConverter(
        new HashBlobId.Factory(),
        new InMemoryMessageId.Factory(),
        new InMemoryId.Factory());
}
 
Example 28
Source Project: paascloud-master   Source File: PcObjectMapper.java    License: Apache License 2.0 5 votes vote down vote up
public static void buidMvcMessageConverter(List<HttpMessageConverter<?>> converters) {
	MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
	SimpleModule simpleModule = new SimpleModule();
	simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
	simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
	ObjectMapper objectMapper = new ObjectMapper()
			.registerModule(new ParameterNamesModule())
			.registerModule(new Jdk8Module())
			.registerModule(new JavaTimeModule())
			.registerModule(simpleModule);
	objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	jackson2HttpMessageConverter.setObjectMapper(objectMapper);
	converters.add(jackson2HttpMessageConverter);
}
 
Example 29
Source Project: hazelcast-jet-demos   Source File: JSONSerializable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Produces a string containing a JSON representation of the object. The
 * default implementation just falls back to Jackson Java 8 serialization
 * 
 * @return A {@code String} containing JSON
 */
public default String toJSONString() {
    try {
        final ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(new Jdk8Module());
        return mapper.writeValueAsString(this);
    } catch (JsonProcessingException jsonx) {
        throw new RuntimeException(jsonx);
    }
}
 
Example 30
Source Project: conjure   Source File: ConjureParser.java    License: Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static ObjectMapper createConjureParserObjectMapper() {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory())
            .registerModule(new Jdk8Module())
            .setAnnotationIntrospector(AnnotationIntrospector.pair(
                    new KebabCaseEnforcingAnnotationInspector(), // needs to come first.
                    new JacksonAnnotationIntrospector()));
    mapper.enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION);
    return mapper;
}