Java Code Examples for com.fasterxml.jackson.databind.module.SimpleModule#setMixInAnnotation()

The following examples show how to use com.fasterxml.jackson.databind.module.SimpleModule#setMixInAnnotation() . 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: ProblemModule.java    From problem with MIT License 6 votes vote down vote up
@Override
public void setupModule(final SetupContext context) {
    final SimpleModule module = new SimpleModule();

    module.setMixInAnnotation(Exceptional.class, stackTraces ?
            ExceptionalMixin.class :
            ExceptionalWithoutStacktraceMixin.class);

    module.setMixInAnnotation(DefaultProblem.class, AbstractThrowableProblemMixIn.class);
    module.setMixInAnnotation(Problem.class, ProblemMixIn.class);

    module.addSerializer(StatusType.class, new StatusTypeSerializer());
    module.addDeserializer(StatusType.class, new StatusTypeDeserializer(statuses));

    module.setupModule(context);
}
 
Example 2
Source File: MarshallerService.java    From dawnsci with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private void applyMarshallersToModule(SimpleModule module, List<IMarshaller> marshallers) throws InstantiationException, IllegalAccessException {
	for (IMarshaller marshaller : marshallers) {
		Class<?> objectClass = marshaller.getObjectClass();
		if (objectClass!=null) {
			module.addSerializer(objectClass,  (JsonSerializer)marshaller.getSerializerClass().newInstance());
			module.addDeserializer(objectClass,(JsonDeserializer)marshaller.getDeserializerClass().newInstance());
		}

		Class<?> mixInType  = marshaller.getMixinAnnotationType();
		Class<?> mixInClass = marshaller.getMixinAnnotationClass();
		if (mixInClass!=null && mixInType!=null) {
			module.setMixInAnnotation(mixInType, mixInClass);
		}
	}
}
 
Example 3
Source File: JacksonCustomizations.java    From sos with Apache License 2.0 5 votes vote down vote up
@Bean
SimpleModule ordersModule() {

	SimpleModule simpleModule = new SimpleModule();
	simpleModule.setMixInAnnotation(ProductInfo.ProductNumber.class, ProductNumberMixin.class);

	return simpleModule;
}
 
Example 4
Source File: ObjectMapperFactory.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Inject
public ObjectMapperFactory(MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory) {
    SimpleModule mailboxIdModule = new SimpleModule();
    mailboxIdModule.addDeserializer(MailboxId.class, new MailboxIdDeserializer(mailboxIdFactory));
    mailboxIdModule.addSerializer(MailboxId.class, new MailboxIdSerializer());
    mailboxIdModule.addKeyDeserializer(MailboxId.class, new MailboxIdKeyDeserializer(mailboxIdFactory));
    mailboxIdModule.addKeySerializer(MailboxId.class, new MailboxIdKeySerializer());

    mailboxIdModule.addDeserializer(MessageId.class, new MessageIdDeserializer(messageIdFactory));
    mailboxIdModule.addSerializer(MessageId.class, new MessageIdSerializer());
    mailboxIdModule.addKeyDeserializer(MessageId.class, new MessageIdKeyDeserializer(messageIdFactory));
    mailboxIdModule.addKeySerializer(MessageId.class, new MessageIdKeySerializer());
    mailboxIdModule.addSerializer(Username.class, new UsernameSerializer());
    mailboxIdModule.addDeserializer(Username.class, new UsernameDeserializer());
    mailboxIdModule.addKeyDeserializer(Username.class, new UsernameKeyDeserializer());
    mailboxIdModule.addKeySerializer(Username.class, new UsernameKeySerializer());
    mailboxIdModule.addDeserializer(Rights.Right.class, new RightDeserializer());

    SimpleModule mdnModule = new SimpleModule();
    mailboxIdModule.addDeserializer(DispositionActionMode.class, new MDNActionModeDeserializer());
    mailboxIdModule.addDeserializer(DispositionSendingMode.class, new MDNSendingModeDeserializer());
    mailboxIdModule.addDeserializer(DispositionType.class, new MDNTypeDeserializer());

    SimpleModule contentTypeModule = new SimpleModule();
    contentTypeModule.addDeserializer(ContentType.class, new ContentTypeDeserializer());
    contentTypeModule.addSerializer(ContentType.class, new ContentTypeSerializer());

    mailboxIdModule.setMixInAnnotation(Role.class, RoleMixIn.class);

    jacksonModules = JACKSON_BASE_MODULES.add(mailboxIdModule)
        .add(mdnModule)
        .add(contentTypeModule)
        .build();
}
 
Example 5
Source File: CardshifterIO.java    From Cardshifter with Apache License 2.0 5 votes vote down vote up
public static void configureMapper(ObjectMapper mapper) {
	mapper.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false);
	mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
	mapper.registerSubtypes(DeckConfig.class);
	
	SimpleModule module = new SimpleModule("", new Version(0, 5, 0, "", "com.cardshifter", "cardshifter"));
	module.setMixInAnnotation(DeckConfig.class, MixinDeckConfig.class);
	module.setMixInAnnotation(Message.class, MixinMessage.class);
       module.setMixInAnnotation(CardInfoMessage.class, MixinCardInfoMessage.class);
       module.setMixInAnnotation(PlayerConfigMessage.class, MixinPlayerConfigMessage.class);
	module.setMixInAnnotation(ErrorMessage.class, MixinErrorMessage.class);
	mapper.registerModule(module);
}
 
Example 6
Source File: JsonMessageSerializerModule.java    From joynr with Apache License 2.0 5 votes vote down vote up
public JsonMessageSerializerModule() {
    objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
    objectMapper.configure(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY, true);
    // objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
    objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, true);
    objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);

    objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName");
    TypeResolverBuilder<?> joynrTypeResolverBuilder = objectMapper.getSerializationConfig()
                                                                  .getDefaultTyper(SimpleType.construct(Object.class));

    SimpleModule module = new SimpleModule("NonTypedModule", new Version(1, 0, 0, "", "", ""));
    module.addSerializer(new JoynrEnumSerializer());
    module.addSerializer(new JoynrListSerializer());
    module.addSerializer(new JoynrArraySerializer());

    TypeDeserializer typeDeserializer = joynrTypeResolverBuilder.buildTypeDeserializer(objectMapper.getDeserializationConfig(),
                                                                                       SimpleType.construct(Object.class),
                                                                                       null);

    module.addDeserializer(Request.class, new RequestDeserializer(objectMapper));
    module.addDeserializer(OneWayRequest.class, new OneWayRequestDeserializer(objectMapper));
    module.addDeserializer(Object.class, new JoynrUntypedObjectDeserializer(typeDeserializer));

    module.setMixInAnnotation(Throwable.class, ThrowableMixIn.class);
    objectMapper.registerModule(module);
}
 
Example 7
Source File: MarshallerService.java    From dawnsci with Eclipse Public License 1.0 4 votes vote down vote up
private final ObjectMapper createJacksonMapper() throws InstantiationException, IllegalAccessException, CoreException {

		ObjectMapper mapper = new ObjectMapper();

		// Use custom serialization for IPosition objects
		// (Otherwise all IPosition subclasses will need to become simple beans, i.e. no-arg constructors with getters
		// and setters for all fields. MapPosition.getNames() caused problems because it just returns keys from the map
		// and has no corresponding setter.)
		SimpleModule module = new SimpleModule();

		// Add mix-in annotations for ROIs
		module.setMixInAnnotation(IROI.class, IROIMixIn.class);
		module.setMixInAnnotation(IOrientableROI.class, IOrientableROIMixIn.class);
		module.setMixInAnnotation(LinearROI.class, LinearROIMixIn.class);
		module.setMixInAnnotation(CircularROI.class, CircularROIMixIn.class);
		module.setMixInAnnotation(GridROI.class, GridROIMixIn.class);
		module.setMixInAnnotation(PerimeterBoxROI.class, PerimeterROIMixIn.class);
		module.setMixInAnnotation(IRectangularROI.class, IRectangularROIMixIn.class);
		module.setMixInAnnotation(RectangularROI.class, RectangularROIMixIn.class);
		module.setMixInAnnotation(RingROI.class, RingROIMixIn.class);
		module.setMixInAnnotation(SectorROI.class, SectorROIMixIn.class);
		module.setMixInAnnotation(FreeDrawROI.class, FreeDrawROIMixIn.class);
		module.setMixInAnnotation(PolylineROI.class, PolylineROIMixIn.class);
		module.setMixInAnnotation(PolygonalROI.class, PolygonalROIMixIn.class);
		module.setMixInAnnotation(XAxisBoxROI.class, XAxisBoxROIMixIn.class);
		module.setMixInAnnotation(YAxisBoxROI.class, YAxisBoxROIMixIn.class);
		module.setMixInAnnotation(EllipticalROI.class, EllipticalROIMixIn.class);
		module.setMixInAnnotation(CircularFitROI.class, CircularFitROIMixIn.class);
		module.setMixInAnnotation(EllipticalFitROI.class, EllipticalFitMixIn.class);
		module.setMixInAnnotation(ParabolicROI.class, ParabolicROIMixIn.class);
		module.setMixInAnnotation(HyperbolicROI.class, HyperbolicROIMixIn.class);

		// Add handlers
		createModuleExtensions(module);

		mapper.registerModule(module);

		// Be careful adjusting these settings - changing them will probably cause various unit tests to fail which
		// check the exact contents of the serialized JSON string
		mapper.setSerializationInclusion(Include.NON_NULL);
		mapper.enable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS);
		mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
		//mapper.enable(SerializationFeature.INDENT_OUTPUT);
		return mapper;
	}