com.fasterxml.jackson.databind.module.SimpleSerializers Java Examples

The following examples show how to use com.fasterxml.jackson.databind.module.SimpleSerializers. 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 File: SchemaSerializationModuleTest.java    From data-highway with Apache License 2.0 6 votes vote down vote up
@Test
public void setupModule() throws JsonMappingException {
  SetupContext context = mock(SetupContext.class);

  underTest.setupModule(context);

  ArgumentCaptor<SimpleSerializers> serializersCaptor = ArgumentCaptor.forClass(SimpleSerializers.class);
  ArgumentCaptor<SimpleDeserializers> deserializersCaptor = ArgumentCaptor.forClass(SimpleDeserializers.class);

  verify(context).addSerializers(serializersCaptor.capture());
  verify(context).addDeserializers(deserializersCaptor.capture());

  JavaType javaType = new ObjectMapper().constructType(Schema.class);

  JsonSerializer<?> serializer = serializersCaptor.getValue().findSerializer(null, javaType, null);
  assertThat(serializer, is(instanceOf(SchemaSerializer.class)));

  JsonDeserializer<?> deserializer = deserializersCaptor.getValue().findBeanDeserializer(javaType, null, null);
  assertThat(deserializer, is(instanceOf(SchemaDeserializer.class)));
}
 
Example #2
Source File: MoneyModule.java    From jackson-datatype-money with MIT License 6 votes vote down vote up
@Override
public void setupModule(final SetupContext context) {
    final SimpleSerializers serializers = new SimpleSerializers();
    serializers.addSerializer(CurrencyUnit.class, new CurrencyUnitSerializer());
    serializers.addSerializer(MonetaryAmount.class, new MonetaryAmountSerializer(names, writer, formatFactory));
    context.addSerializers(serializers);

    final SimpleDeserializers deserializers = new SimpleDeserializers();
    deserializers.addDeserializer(CurrencyUnit.class, new CurrencyUnitDeserializer());
    deserializers.addDeserializer(MonetaryAmount.class, new MonetaryAmountDeserializer<>(amountFactory, names));
    // for reading into concrete implementation types
    deserializers.addDeserializer(Money.class, new MonetaryAmountDeserializer<>(moneyFactory, names));
    deserializers.addDeserializer(FastMoney.class, new MonetaryAmountDeserializer<>(fastMoneyFactory, names));
    deserializers.addDeserializer(RoundedMoney.class, new MonetaryAmountDeserializer<>(roundedMoneyFactory, names));
    context.addDeserializers(deserializers);
}
 
Example #3
Source File: RosettaObjectMapperTest.java    From Rosetta with Apache License 2.0 5 votes vote down vote up
private static void registerSerializer(ConfigRegistry config, JsonSerializer<TestObject> serializer) {
  ObjectMapper objectMapper = new ObjectMapper();
  SimpleModule module = new SimpleModule();
  module.setSerializers(new SimpleSerializers(Collections.singletonList(serializer)));
  objectMapper.registerModule(module);

  config.get(RosettaObjectMapper.class).setObjectMapper(objectMapper);
}
 
Example #4
Source File: JacksonPinpointModule.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
    SimpleSerializers serializers = new SimpleSerializers();
    serializers.addSerializer(ServiceType.class, new ServiceTypeSerializer());
    
    context.addSerializers(serializers);
}
 
Example #5
Source File: NakadiMetricsModule.java    From nakadi with MIT License 5 votes vote down vote up
@Override
public void setupModule(final SetupContext context) {
    context.addSerializers(new SimpleSerializers(Arrays.<JsonSerializer<?>>asList(
            new GaugeSerializer(),
            new CounterSerializer(),
            new HistogramSerializer(showSamples),
            new MeterSerializer(rateUnit),
            new TimerSerializer(rateUnit, durationUnit, showSamples),
            new MetricRegistrySerializer(filter)
    )));
}
 
Example #6
Source File: SortJacksonModule.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
	SimpleSerializers serializers = new SimpleSerializers();
	serializers.addSerializer(Sort.class, new SortJsonComponent.SortSerializer());
	context.addSerializers(serializers);

	SimpleDeserializers deserializers = new SimpleDeserializers();
	deserializers.addDeserializer(Sort.class,
			new SortJsonComponent.SortDeserializer());
	context.addDeserializers(deserializers);
}
 
Example #7
Source File: FilterObjectMapperBuilderTest.java    From jfilter with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigureSerializersTrue() {
    SerializerFactoryConfig serializerFactoryConfig = getFactoryConfig(filterObjectMapperTrue);

    boolean jdk8SerializerExist = serializerExist(serializerFactoryConfig.serializers(), Jdk8Serializers.class);
    assertTrue(jdk8SerializerExist);

    boolean simpleSerializerExist = serializerExist(serializerFactoryConfig.serializers(), SimpleSerializers.class);
    assertTrue(simpleSerializerExist);
}
 
Example #8
Source File: FilterObjectMapperBuilderTest.java    From jfilter with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigureSerializersFalse() {
    SerializerFactoryConfig serializerFactoryConfig = getFactoryConfig(filterObjectMapperFalse);

    boolean jdk8SerializerExist = serializerExist(serializerFactoryConfig.serializers(), Jdk8Serializers.class);
    assertFalse(jdk8SerializerExist);

    boolean simpleSerializerExist = serializerExist(serializerFactoryConfig.serializers(), SimpleSerializers.class);
    assertFalse(simpleSerializerExist);
}
 
Example #9
Source File: MetricsElasticsearchModule.java    From oneops with Apache License 2.0 5 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
    context.addSerializers(new SimpleSerializers(Arrays.<JsonSerializer<?>>asList(
            new GaugeSerializer(timestampFieldname),
            new CounterSerializer(timestampFieldname),
            new HistogramSerializer(timestampFieldname),
            new MeterSerializer(rateUnit, timestampFieldname),
            new TimerSerializer(rateUnit, durationUnit, timestampFieldname),
            new BulkIndexOperationHeaderSerializer(timestampFieldname)
    )));
}
 
Example #10
Source File: DmJacksonModule.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Method called by {@link ObjectMapper} when module is registered.
 * It is called to let module register functionality it provides,
 * using callback methods passed-in context object exposes.
 */
@Override
public void setupModule(SetupContext setupContext) {
    SimpleSerializers serializers = new SimpleSerializers();
    addSerializers(serializers);
    setupContext.addSerializers(serializers);

    SimpleDeserializers deserializers = new SimpleDeserializers();
    addDeserializers(deserializers);
    setupContext.addDeserializers(deserializers);
    setupContext.addBeanDeserializerModifier(new KeeperBeanDeserializerModifier());
}
 
Example #11
Source File: JobJacksonModule.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void setupModule(SetupContext setupContext) {
    SimpleSerializers serializers = new SimpleSerializers();
    addSerializers(serializers);
    setupContext.addSerializers(serializers);

    SimpleDeserializers deserializers = new SimpleDeserializers();
    addDeserializers(deserializers);
    setupContext.addDeserializers(deserializers);
}
 
Example #12
Source File: ProtobufModule.java    From jackson-datatype-protobuf with Apache License 2.0 4 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
  SimpleSerializers serializers = new SimpleSerializers();
  serializers.addSerializer(new MessageSerializer(config));
  serializers.addSerializer(new DurationSerializer());
  serializers.addSerializer(new FieldMaskSerializer());
  serializers.addSerializer(new ListValueSerializer());
  serializers.addSerializer(new NullValueSerializer());
  serializers.addSerializer(new StructSerializer());
  serializers.addSerializer(new TimestampSerializer());
  serializers.addSerializer(new ValueSerializer());
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(DoubleValue.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(FloatValue.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(Int64Value.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(UInt64Value.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(Int32Value.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(UInt32Value.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(BoolValue.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(StringValue.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(BytesValue.class));

  context.addSerializers(serializers);

  context.addDeserializers(new MessageDeserializerFactory(config));
  SimpleDeserializers deserializers = new SimpleDeserializers();
  deserializers.addDeserializer(Duration.class, new DurationDeserializer());
  deserializers.addDeserializer(FieldMask.class, new FieldMaskDeserializer());
  deserializers.addDeserializer(ListValue.class, new ListValueDeserializer().buildAtEnd());
  deserializers.addDeserializer(NullValue.class, new NullValueDeserializer());
  deserializers.addDeserializer(Struct.class, new StructDeserializer().buildAtEnd());
  deserializers.addDeserializer(Timestamp.class, new TimestampDeserializer());
  deserializers.addDeserializer(Value.class, new ValueDeserializer().buildAtEnd());
  deserializers.addDeserializer(DoubleValue.class, wrappedPrimitiveDeserializer(DoubleValue.class));
  deserializers.addDeserializer(FloatValue.class, wrappedPrimitiveDeserializer(FloatValue.class));
  deserializers.addDeserializer(Int64Value.class, wrappedPrimitiveDeserializer(Int64Value.class));
  deserializers.addDeserializer(UInt64Value.class, wrappedPrimitiveDeserializer(UInt64Value.class));
  deserializers.addDeserializer(Int32Value.class, wrappedPrimitiveDeserializer(Int32Value.class));
  deserializers.addDeserializer(UInt32Value.class, wrappedPrimitiveDeserializer(UInt32Value.class));
  deserializers.addDeserializer(BoolValue.class, wrappedPrimitiveDeserializer(BoolValue.class));
  deserializers.addDeserializer(StringValue.class, wrappedPrimitiveDeserializer(StringValue.class));
  deserializers.addDeserializer(BytesValue.class, wrappedPrimitiveDeserializer(BytesValue.class));
  context.addDeserializers(deserializers);
  context.setMixInAnnotations(MessageOrBuilder.class, MessageOrBuilderMixin.class);
}
 
Example #13
Source File: SchemaSerializationModule.java    From data-highway with Apache License 2.0 4 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
  context.addSerializers(new SimpleSerializers(Collections.singletonList(new SchemaSerializer())));
  context.addDeserializers(new SimpleDeserializers(Collections.singletonMap(Schema.class, new SchemaDeserializer())));
}
 
Example #14
Source File: DmJacksonModule.java    From haven-platform with Apache License 2.0 4 votes vote down vote up
private void addSerializers(SimpleSerializers serializers) {
    serializers.addSerializer(MimeType.class, new MimeTypeSerializer());
    serializers.addSerializer(Keeper.class, new KeeperSerializer());
}
 
Example #15
Source File: JobJacksonModule.java    From haven-platform with Apache License 2.0 4 votes vote down vote up
private void addSerializers(SimpleSerializers serializers) {
    if(jobParameterDescriptionSerializer != null) {
        serializers.addSerializer(JobParameterDescription.class, jobParameterDescriptionSerializer);
    }
}
 
Example #16
Source File: Jackson2ObjectMapperFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
	SimpleSerializers serializers = new SimpleSerializers();
	serializers.addSerializer(Integer.class, new CustomIntegerSerializer());
	context.addSerializers(serializers);
}
 
Example #17
Source File: Jackson2ObjectMapperBuilderTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
	SimpleSerializers serializers = new SimpleSerializers();
	serializers.addSerializer(Integer.class, new CustomIntegerSerializer());
	context.addSerializers(serializers);
}
 
Example #18
Source File: Jackson2ObjectMapperFactoryBeanTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
	SimpleSerializers serializers = new SimpleSerializers();
	serializers.addSerializer(Integer.class, new CustomIntegerSerializer());
	context.addSerializers(serializers);
}
 
Example #19
Source File: Jackson2ObjectMapperBuilderTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
	SimpleSerializers serializers = new SimpleSerializers();
	serializers.addSerializer(Integer.class, new CustomIntegerSerializer());
	context.addSerializers(serializers);
}
 
Example #20
Source File: WorkflowController.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@PostMapping(value = "/getMailingsByWorkStatus.action", produces = HttpUtils.APPLICATION_JSON_UTF8)
public @ResponseBody ResponseEntity<?> getMailingsByWorkStatus(ComAdmin admin,
                        @RequestParam(value = "mailingId", required = false, defaultValue = "0") int mailingId,
                        @RequestParam("mailingTypes") String mailingTypes,
                        @RequestParam("status") String status,
                        @RequestParam(value = "mailingStatus", required = false) String mailingStatus,
                        @RequestParam(value = "takeMailsForPeriod", required = false) String takeMailsForPeriodParam,
                        @RequestParam(value = "parentMailingId", required = false, defaultValue = "0") int parentMailingId,
                        @RequestParam("sort") String sort,
                        @RequestParam("order") String order,
                        @RequestParam(value = "mailingsInCampaign", required = false) String mailingsInCampaign
) throws Exception {
    int companyId = admin.getCompanyID();

    if (StringUtils.isEmpty(mailingTypes)) {
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    } else {
        List<Integer> mailingTypeList = com.agnitas.reporting.birt.external.utils.StringUtils.buildListFormCommaSeparatedValueString(mailingTypes);
        boolean takeMailsForPeriod = Boolean.parseBoolean(takeMailsForPeriodParam);

        List<Map<String, Object>> mailings = workflowService.getAllMailings(admin, mailingTypeList,
                status, mailingStatus, takeMailsForPeriod, sort, order);


        if (StringUtils.isNotBlank(mailingsInCampaign)) {
            mailings.addAll(workflowService.getMailings(companyId, mailingsInCampaign));
        }

        boolean parentNotInList = true;
        for (Map<String, Object> mailing : mailings) {
            if (((Number) mailing.get("MAILING_ID")).intValue() == parentMailingId) {
                parentNotInList = false;
                break;
            }
        }

        if (parentNotInList && (parentMailingId != 0) && (parentMailingId != mailingId)) {
            Map<String, Object> mailingData = workflowService.getMailingWithWorkStatus(parentMailingId, companyId);
            mailings.add(mailingData);
        }

        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new SimpleModule("", Version.unknownVersion()) {
            private static final long serialVersionUID = -4563093834218254808L;

            @Override
            public void setupModule(SetupContext context) {
                SimpleSerializers serializers = new SimpleSerializers();
                serializers.addSerializer(String.class, new UpperCaseKeySerializer());
                context.addKeySerializers(serializers);
            }
        });

        return new ResponseEntity<>(objectMapper.writeValueAsString(mailings), HttpStatus.OK);
    }
}
 
Example #21
Source File: Jackson2ObjectMapperFactoryBeanTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
	SimpleSerializers serializers = new SimpleSerializers();
	serializers.addSerializer(Integer.class, new CustomIntegerSerializer());
	context.addSerializers(serializers);
}
 
Example #22
Source File: Jackson2ObjectMapperBuilderTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
	SimpleSerializers serializers = new SimpleSerializers();
	serializers.addSerializer(Integer.class, new CustomIntegerSerializer());
	context.addSerializers(serializers);
}