List of usage examples for com.fasterxml.jackson.databind ObjectMapper setVisibility
public ObjectMapper setVisibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility)
From source file:com.ikanow.aleph2.data_model.utils.BeanTemplateUtils.java
/** Configures a mapper with the desired properties for use in Aleph2 * @param configure_me - leave this empty to create a new mapper, or add one to configure an existing mapper * @return//www.j a v a2 s. c o m */ public static ObjectMapper configureMapper(final Optional<ObjectMapper> configure_me) { final ObjectMapper mapper = configure_me.orElse(new ObjectMapper()); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); mapper.setSerializationInclusion(Include.NON_NULL); mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE); final SimpleModule module = new SimpleModule(); module.addDeserializer(Number.class, new NumberDeserializer()); mapper.registerModule(module); return mapper; }
From source file:org.talend.components.webtest.TestApplication.java
@Bean public Jackson2ObjectMapperBuilder jacksonBuilder() { return new Jackson2ObjectMapperBuilder() { @Override/*w w w.j a va 2 s.c o m*/ public void configure(ObjectMapper objectMapper) { super.configure(objectMapper); objectMapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE); objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); } }; }
From source file:io.blobkeeper.server.configuration.ServerConfiguration.java
@Provides @Singleton/*from w w w . j a v a2 s . com*/ public ObjectMapper objectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibility(FIELD, ANY); return mapper; }
From source file:com.siemens.sw360.datahandler.couchdb.MapperFactory.java
/** * Creates an object mapper with the given personalization * * @return the personalized object mapper *//*from w ww . jav a 2 s .c o m*/ @Override public ObjectMapper createObjectMapper() { ObjectMapper mapper = new ObjectMapper(); // General settings mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); // auto-detect all member fields mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE); // but only public getters mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE); // and none of "is-setters" // Do not include null mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // Classes mix-in for (Class type : classes) { mapper.addMixInAnnotations(type, DatabaseMixIn.class); } // Nested classes mix-in for (Class type : nestedClasses) { mapper.addMixInAnnotations(type, DatabaseNestedMixIn.class); } return mapper; }
From source file:org.opendaylight.ovsdb.lib.message.MonitorResponseTest.java
public void testDeser() throws IOException { URL resource = Resources.getResource(MonitorResponseTest.class, "monitor_response1.json"); InputSupplier<InputStream> inputStreamInputSupplier = Resources.newInputStreamSupplier(resource); InputStream input = inputStreamInputSupplier.getInput(); ObjectMapper mapper = new ObjectMapper(); mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.ANY); TableUpdates updates = mapper.readValue(input, TableUpdates.class); Set<Table.Name> available = updates.availableUpdates(); for (Table.Name name : available) { if (Bridge.NAME.equals(name)) { verifyBridge(updates);//from w ww .j a va 2s . c o m } else if (Port.NAME.equals(name)) { veriftyPort(updates); } else if (Interface.NAME.equals(name)) { verifyInterface(updates); } } }
From source file:it.bz.tis.integreen.carsharingbzit.api.ApiClient.java
public <T> T callWebService(ServiceRequest request, Class<T> clazz) throws IOException { request.request.technicalUser.username = this.user; request.request.technicalUser.password = this.password; ObjectMapper mapper = new ObjectMapper(); mapper.setVisibility(PropertyAccessor.FIELD, Visibility.NONE) .setVisibility(PropertyAccessor.IS_GETTER, Visibility.PUBLIC_ONLY) .setVisibility(PropertyAccessor.GETTER, Visibility.PUBLIC_ONLY) .setVisibility(PropertyAccessor.SETTER, Visibility.PUBLIC_ONLY); mapper.enable(SerializationFeature.INDENT_OUTPUT); StringWriter sw = new StringWriter(); mapper.writeValue(sw, request);//from ww w . j ava2 s.c o m String requestJson = sw.getBuffer().toString(); logger.debug("callWebService(): jsonRequest:" + requestJson); URL url = new URL(this.endpoint); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true); OutputStream out = conn.getOutputStream(); out.write(requestJson.getBytes("UTF-8")); out.flush(); int responseCode = conn.getResponseCode(); InputStream input = conn.getInputStream(); ByteArrayOutputStream data = new ByteArrayOutputStream(); int len; byte[] buf = new byte[50000]; while ((len = input.read(buf)) > 0) { data.write(buf, 0, len); } conn.disconnect(); String jsonResponse = new String(data.toByteArray(), "UTF-8"); if (responseCode != 200) { throw new IOException(jsonResponse); } logger.debug("callWebService(): jsonResponse:" + jsonResponse); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); T response = mapper.readValue(new StringReader(jsonResponse), clazz); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); sw = new StringWriter(); mapper.writeValue(sw, response); logger.debug( "callWebService(): parsed response into " + response.getClass().getName() + ":" + sw.toString()); return response; }
From source file:org.springframework.session.data.mongo.JacksonMongoSessionConverter.java
private ObjectMapper buildObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); // serialize fields instead of properties objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE); objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); // ignore unresolved fields (mostly 'principal') objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.setPropertyNamingStrategy(new MongoIdNamingStrategy()); return objectMapper; }
From source file:com.bodybuilding.argos.controller.StreamController.java
@Autowired public StreamController(ClusterRegistry registry, Observable<Boolean> shutdown) { Objects.requireNonNull(registry); Objects.requireNonNull(shutdown); ObjectMapper om = new ObjectMapper(); om.enable(MapperFeature.AUTO_DETECT_FIELDS); om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); Observable<HystrixClusterMetrics> metricsObs = registry.observe(); streamObservable = metricsObs.takeUntil(shutdown).map(d -> { try {//www . ja va 2s . co m return om.writeValueAsString(d); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }).share(); }
From source file:net.nikore.gozer.marathon.MarathonModule.java
@Provides @Singleton//w ww . j av a 2 s. co m ObjectMapper provideObjectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); return mapper; }
From source file:cc.arduino.packages.discoverers.PluggableDiscovery.java
@Override public void run() { // this method is started as a new thread, it will constantly listen // to the discovery tool and keep track of the discovered ports try {//from w ww.j a v a 2 s . co m start(); InputStream input = program.getInputStream(); JsonFactory factory = new JsonFactory(); JsonParser parser = factory.createParser(input); ObjectMapper mapper = new ObjectMapper(); mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE); mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); while (program != null && program.isAlive()) { JsonNode tree = mapper.readTree(parser); if (tree == null) { if (program != null && program.isAlive()) { System.err.println(format("{0}: Invalid json message", discoveryName)); } break; } debug("Received json: " + tree); processJsonNode(mapper, tree); } debug("thread exit normally"); } catch (InterruptedException e) { debug("thread exit by interrupt"); e.printStackTrace(); } catch (Exception e) { debug("thread exit other exception"); e.printStackTrace(); } try { stop(); } catch (Exception e) { } }