List of usage examples for com.fasterxml.jackson.databind ObjectMapper addMixInAnnotations
public final void addMixInAnnotations(Class<?> target, Class<?> mixinSource)
From source file:com.titan.main.Invoker.java
public static void main(String... args) { try {/*from w w w . j a v a 2 s . c o m*/ NotificationsFactory factory = new NotificationsFactory(); ObjectMapper mapper = new ObjectMapper(); mapper.addMixInAnnotations(Notifications.class, NotificationsMixin.class); mapper.addMixInAnnotations(NotificationsInfo.class, NotificationsInfoMixin.class); Notifications notifications = factory.getNotifications(); mapper.writerWithDefaultPrettyPrinter().writeValue( new File("D:/workspace/nbworkspace/jackson-sample/notifications.json"), notifications); System.out.println("Done!"); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.nmdp.service.feature.client.FeatureServiceModule.java
@Provides @Singleton// ww w. j a va 2 s . co m static FeatureService createFeatureService(@EndpointUrl final String endpointUrl) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.addMixInAnnotations(Feature.class, FeatureMixIn.class); return new RestAdapter.Builder().setEndpoint(endpointUrl).setConverter(new JacksonConverter(objectMapper)) .build().create(FeatureService.class); }
From source file:io.fabric8.jenkins.openshiftsync.OpenShiftUtils.java
public static String dumpWithoutRuntimeStateAsYaml(HasMetadata obj) throws JsonProcessingException { ObjectMapper statelessMapper = new ObjectMapper(new YAMLFactory()); statelessMapper.addMixInAnnotations(ObjectMeta.class, ObjectMetaMixIn.class); statelessMapper.addMixInAnnotations(ReplicationController.class, StatelessReplicationControllerMixIn.class); return statelessMapper.writeValueAsString(obj); }
From source file:org.ng200.openolympus.factory.JacksonSerializationFactory.java
/** * @return Jackson ObjectMapper that has the necessary configuration to * serialise and deserialise Cerberus classes */// w w w. j a v a 2 s.c o m public static ObjectMapper createObjectMapper() { ObjectMapper objectMapper = new ObjectMapper().enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL) .registerModule(new PathSerializationModule()).registerModule(new Jdk8Module()) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); try { objectMapper.addMixInAnnotations(Path.class, PathMixin.class); objectMapper.addMixInAnnotations(Class.forName("sun.nio.fs.UnixPath"), PathMixin.class); return objectMapper; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:ch.rasc.extclassgenerator.ModelAnnotationProcessor.java
private static String generateSubclassCode(Class<?> clazz, OutputConfig outputConfig) { Model modelAnnotation = clazz.getAnnotation(Model.class); String name;/* w ww. ja va2 s .c om*/ if (modelAnnotation != null && StringUtils.hasText(modelAnnotation.value())) { name = modelAnnotation.value(); } else { name = clazz.getName(); } Map<String, Object> modelObject = new LinkedHashMap<String, Object>(); modelObject.put("extend", name + "Base"); StringBuilder sb = new StringBuilder(100); sb.append("Ext.define(\"").append(name).append("\","); if (outputConfig.isDebug()) { sb.append("\n"); } String configObjectString; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, false); if (!outputConfig.isSurroundApiWithQuotes()) { if (outputConfig.getOutputFormat() == OutputFormat.EXTJS5) { mapper.addMixInAnnotations(ProxyObject.class, ProxyObjectWithoutApiQuotesExtJs5Mixin.class); } else { mapper.addMixInAnnotations(ProxyObject.class, ProxyObjectWithoutApiQuotesMixin.class); } mapper.addMixInAnnotations(ApiObject.class, ApiObjectMixin.class); } else { if (outputConfig.getOutputFormat() != OutputFormat.EXTJS5) { mapper.addMixInAnnotations(ProxyObject.class, ProxyObjectWithApiQuotesMixin.class); } } if (outputConfig.isDebug()) { configObjectString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(modelObject); } else { configObjectString = mapper.writeValueAsString(modelObject); } } catch (JsonGenerationException e) { throw new RuntimeException(e); } catch (JsonMappingException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } sb.append(configObjectString); sb.append(");"); if (outputConfig.isUseSingleQuotes()) { return sb.toString().replace('"', '\''); } return sb.toString(); }
From source file:org.jongo.util.JongoEmbeddedRule.java
public JongoEmbeddedRule withMixIn(final Class<?> spec, final Class<?> mixIn) { mapperBuilder.addModifier(new MapperModifier() { public void modify(ObjectMapper mapper) { mapper.addMixInAnnotations(spec, mixIn); }/*from www . j a v a 2 s.com*/ }); return this; }
From source file:com.github.shyiko.jackson.module.advice.JsonAdviceModuleTest.java
private ObjectMapper objectMapper(Module... modules) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.addMixInAnnotations(User.class, UserMixin.class); for (Module module : modules) { objectMapper.registerModule(module); }// w w w. j av a2 s. c o m return objectMapper; }
From source file:com.amazonaws.dynamodb.bootstrap.AttributeValueMixInTest.java
/** * Test the Mixin to make sure that it capitalizes the values, and is * different from an ObjectMapper without the Mixin. *//*from w w w . ja v a 2 s.co m*/ @Test public void testReturnsCapitalSWithMixin() throws JsonProcessingException { String capitalS = "S"; String lowercaseS = "s"; ObjectMapper mapperWith = new ObjectMapper(); mapperWith.setSerializationInclusion(Include.NON_NULL); mapperWith.addMixInAnnotations(AttributeValue.class, AttributeValueMixIn.class); String withMixIn = mapperWith.writeValueAsString(sampleScanResult().get(0)); ObjectMapper mapperWithout = new ObjectMapper(); mapperWithout.setSerializationInclusion(Include.NON_NULL); String withoutMixIn = mapperWithout.writeValueAsString(sampleScanResult().get(0)); assertTrue(withMixIn.contains(capitalS)); assertTrue(withoutMixIn.contains(lowercaseS)); }
From source file:ObjectMapperProvider.java
@Override public ObjectMapper get() { ObjectMapper mapper = new ObjectMapper(); mapper.configure(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.addMixInAnnotations(ImagePlantAddRequest.class, ImagePlantAddRequestModel.class); mapper.addMixInAnnotations(AmazonS3Bucket.class, AmazonS3BucketModel.class); mapper.addMixInAnnotations(ResizingConfig.class, ResizingConfigModel.class); mapper.addMixInAnnotations(TemplateIdentity.class, TemplateIdentityModel.class); mapper.addMixInAnnotations(TemplateResponse.class, TemplateResponseModel.class); return mapper; }
From source file:net.udidb.server.driver.ServerModule.java
@Override protected void configure() { // JSON configuration SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(ExpressionValue.class, new ExpressionValueSerializer()); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.addMixInAnnotations(VoidResult.class, VoidResultMixIn.class); objectMapper.addMixInAnnotations(DeferredResult.class, DeferredResultMixIn.class); objectMapper.addMixInAnnotations(TableResult.class, TableResultMixIn.class); objectMapper.addMixInAnnotations(ValueResult.class, ValueResultMixIn.class); objectMapper.addMixInAnnotations(TableRow.class, TableRowMixIn.class); objectMapper.registerModule(simpleModule); bind(ObjectMapper.class).toInstance(objectMapper); // REST API configuration Vertx vertx = new VertxFactoryImpl().vertx(); bind(Vertx.class).toInstance(vertx); // Engine configuration bind(String[].class).annotatedWith(Names.named("OP_PACKAGES")) .toInstance(new String[] { "net.udidb.engine.ops.impls" }); bind(DebuggeeContextManager.class).to(DebuggeeContextManagerImpl.class); bind(HelpMessageProvider.class).asEagerSingleton(); bind(UdiProcessManager.class).toInstance(new UdiProcessManagerImpl()); bind(BinaryReader.class).toInstance(new CrossPlatformBinaryReader()); bind(ExpressionCompiler.class).toInstance(new ExpressionCompilerDelegate()); bind(SourceLineRowFactory.class).toInstance(new InMemorySourceLineRowFactory()); bind(ServerEngine.class).to(ServerEngineImpl.class); bind(OperationResultVisitor.class).to(OperationEngine.class); bind(ServerEventDispatcher.class).asEagerSingleton(); bind(EventPump.class).asEagerSingleton(); bind(EventSink.class).to(ServerEventDispatcher.class); WampRouter wampRouter = configureWampRouter(); bind(WampRouter.class).toInstance(wampRouter); bind(WampClient.class).toInstance(configureWampClient(wampRouter)); }