@Test public void setMixIns() { Class<?> target = String.class; Class<?> mixinSource = Object.class; Map<Class<?>, Class<?>> mixIns = new HashMap<>(); mixIns.put(target, mixinSource); this.factory.setModules(Collections.emptyList()); this.factory.setMixIns(mixIns); this.factory.afterPropertiesSet(); ObjectMapper objectMapper = this.factory.getObject(); assertEquals(1, objectMapper.mixInCount()); assertSame(mixinSource, objectMapper.findMixInClassFor(target)); }
@Test public void mixIns() { Class<?> target = String.class; Class<?> mixInSource = Object.class; Map<Class<?>, Class<?>> mixIns = new HashMap<>(); mixIns.put(target, mixInSource); ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json() .modules().mixIns(mixIns) .build(); assertEquals(1, objectMapper.mixInCount()); assertSame(mixInSource, objectMapper.findMixInClassFor(target)); }
@Test public void mixIn() { Class<?> target = String.class; Class<?> mixInSource = Object.class; ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json() .modules().mixIn(target, mixInSource) .build(); assertEquals(1, objectMapper.mixInCount()); assertSame(mixInSource, objectMapper.findMixInClassFor(target)); }
/** * Returns whether the module was already registered in the given {@link ObjectMapper}. * * @param mapper must not be {@literal null}. * @return */ public static boolean isAlreadyRegisteredIn(ObjectMapper mapper) { Assert.notNull(mapper, "ObjectMapper must not be null!"); return LinkMixin.class.equals(mapper.findMixInClassFor(Link.class)); }
/** * Returns whether the module was already registered in the given {@link ObjectMapper}. * * @param mapper must not be {@literal null}. * @return */ public static boolean isAlreadyRegisteredIn(ObjectMapper mapper) { Assert.notNull(mapper, "ObjectMapper must not be null!"); return LinkMixin.class.equals(mapper.findMixInClassFor(Link.class)); }
public static void maybeRegisterModule(ObjectMapper objectMapper) { if (objectMapper.findMixInClassFor(ApiListing.class) == null) { objectMapper.registerModule(new SwaggerJacksonModule()); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); } }
public RabbitClient(MessageBrokerConfig config, RabbitConnection connection) { this.connection = connection; channel = connection.getChannel(); objectMapper = new ObjectMapper(); messageClass = config.getMessageClass(); objectMapper.registerModules(config.getJacksonModules()); objectMapper.addMixIn(Envelope.class, EnvelopeMixin.class); objectMapper.registerModule(new JavaTimeModule()); if (objectMapper.findMixInClassFor(Message.class) == null) { objectMapper.addMixIn(DefaultMessage.class, DefaultMessageMixin.class); } }
public RabbitClient(MessageBrokerConfig config, RabbitConnection connection) { this.connection = connection; channel = connection.getChannel(); objectMapper = new ObjectMapper(); messageClass = config.getMessageClass(); objectMapper.registerModules(config.getJacksonModules()); objectMapper.addMixIn(Envelope.class, EnvelopeMixin.class); objectMapper.registerModule(new JavaTimeModule()); if (objectMapper.findMixInClassFor(Message.class) == null) { objectMapper.addMixIn(DefaultMessage.class, DefaultMessageMixin.class); } }