List of usage examples for com.fasterxml.jackson.databind ObjectMapper setVisibility
public ObjectMapper setVisibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility)
From source file:org.apereo.portal.events.aggr.JpaStatisticalSummaryTest.java
public void testStorelessUnivariateStatistic(StorelessUnivariateStatistic sus, double expected) throws Exception { assertEquals(expected, sus.getResult(), 0.1); final ObjectMapper mapper = new ObjectMapper(); mapper.findAndRegisterModules();/*from w w w . j ava 2s . c o m*/ //Configure Jackson to just use fields mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); mapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE); mapper.setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE); mapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE); mapper.setVisibility(PropertyAccessor.CREATOR, Visibility.NONE); mapper.addMixInAnnotations(Object.class, IgnoreTypeMixIn.class); final FilterProvider filters = new SimpleFilterProvider().addFilter("storedDataFilter", SimpleBeanPropertyFilter.serializeAllExcept("storedData")); final ObjectWriter ssWriter = mapper.writer(filters); final ObjectReader ssReader = mapper.reader(sus.getClass()); final String susString = ssWriter.writeValueAsString(sus); System.out.println(susString); final StorelessUnivariateStatistic newSus = ssReader.readValue(susString); assertEquals(expected, newSus.getResult(), 0.1); }
From source file:org.finra.herd.tools.common.databridge.DataBridgeManifestReader.java
/** * Reads a JSON manifest file into a JSON manifest object. * * @param jsonManifestFile the JSON manifest file. * * @return the manifest object.//from w w w .j a v a 2 s. c om * @throws java.io.IOException if any errors were encountered reading the JSON file. * @throws IllegalArgumentException if the manifest file has validation errors. */ public M readJsonManifest(File jsonManifestFile) throws IOException, IllegalArgumentException { // Verify that the file exists and can be read. HerdFileUtils.verifyFileExistsAndReadable(jsonManifestFile); // Deserialize the JSON manifest. BufferedInputStream buffer = new BufferedInputStream(new FileInputStream(jsonManifestFile)); BufferedReader reader = new BufferedReader(new InputStreamReader(buffer, Charsets.UTF_8)); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); objectMapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE); objectMapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE); M manifest = getManifestFromReader(reader, objectMapper); // Validate the manifest and return it. validateManifest(manifest); return manifest; }
From source file:org.geoserver.notification.geonode.GeoNodeJsonEncoder.java
@Override public byte[] encode(Notification notification) throws Exception { byte[] ret = null; ObjectMapper mapper = new ObjectMapper(); mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'")); mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE); mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); mapper.setSerializationInclusion(Include.NON_NULL); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); KombuMessage message = new KombuMessage(); message.setId(new UID().toString()); message.setType(notification.getType() != null ? notification.getType().name() : null); message.setAction(notification.getAction() != null ? notification.getAction().name() : null); message.setTimestamp(new Date()); message.setUser(notification.getUser()); message.setOriginator(InetAddress.getLocalHost().getHostAddress()); message.setProperties(notification.getProperties()); if (notification.getObject() instanceof NamespaceInfo) { NamespaceInfo obj = (NamespaceInfo) notification.getObject(); KombuNamespaceInfo source = new KombuNamespaceInfo(); source.setId(obj.getId());/*from w w w.j a v a 2 s.c o m*/ source.setType("NamespaceInfo"); source.setName(obj.getName()); source.setNamespaceURI(obj.getURI()); message.setSource(source); } if (notification.getObject() instanceof WorkspaceInfo) { WorkspaceInfo obj = (WorkspaceInfo) notification.getObject(); KombuWorkspaceInfo source = new KombuWorkspaceInfo(); source.setId(obj.getId()); source.setType("WorkspaceInfo"); source.setName(obj.getName()); source.setNamespaceURI(""); message.setSource(source); } if (notification.getObject() instanceof LayerInfo) { LayerInfo obj = (LayerInfo) notification.getObject(); KombuLayerInfo source = new KombuLayerInfo(); source.setId(obj.getId()); source.setType("LayerInfo"); source.setName(obj.getName()); source.setResourceType(obj.getType() != null ? obj.getType().name() : ""); BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer("name"); Collection<String> styleNames = CollectionUtils.collect(obj.getStyles(), transformer); source.setStyles(StringUtils.join(styleNames.toArray())); source.setDefaultStyle(obj.getDefaultStyle() != null ? obj.getDefaultStyle().getName() : ""); ResourceInfo res = obj.getResource(); source.setWorkspace(res.getStore() != null ? res.getStore().getWorkspace() != null ? res.getStore().getWorkspace().getName() : "" : ""); if (res.getNativeBoundingBox() != null) { source.setBounds(new Bounds(res.getNativeBoundingBox())); } if (res.getLatLonBoundingBox() != null) { source.setGeographicBunds(new Bounds(res.getLatLonBoundingBox())); } message.setSource(source); } if (notification.getObject() instanceof LayerGroupInfo) { LayerGroupInfo obj = (LayerGroupInfo) notification.getObject(); KombuLayerGroupInfo source = new KombuLayerGroupInfo(); source.setId(obj.getId()); source.setType("LayerGroupInfo"); source.setName(obj.getName()); source.setWorkspace(obj.getWorkspace() != null ? obj.getWorkspace().getName() : ""); source.setMode(obj.getType().name()); String rootStyle = obj.getRootLayerStyle() != null ? obj.getRootLayerStyle().getName() : ""; source.setRootLayerStyle(rootStyle); source.setRootLayer(obj.getRootLayer() != null ? obj.getRootLayer().getPath() : ""); for (PublishedInfo pl : obj.getLayers()) { KombuLayerSimpleInfo kl = new KombuLayerSimpleInfo(); if (pl instanceof LayerInfo) { LayerInfo li = (LayerInfo) pl; kl.setName(li.getName()); String lstyle = li.getDefaultStyle() != null ? li.getDefaultStyle().getName() : ""; if (!lstyle.equals(rootStyle)) { kl.setStyle(lstyle); } source.addLayer(kl); } } message.setSource(source); } if (notification.getObject() instanceof ResourceInfo) { ResourceInfo obj = (ResourceInfo) notification.getObject(); KombuResourceInfo source = null; if (notification.getObject() instanceof FeatureTypeInfo) { source = new KombuFeatureTypeInfo(); source.setType("FeatureTypeInfo"); } if (notification.getObject() instanceof CoverageInfo) { source = new KombuCoverageInfo(); source.setType("CoverageInfo"); } if (notification.getObject() instanceof WMSLayerInfo) { source = new KombuWMSLayerInfo(); source.setType("WMSLayerInfo"); } if (source != null) { source.setId(obj.getId()); source.setName(obj.getName()); source.setWorkspace(obj.getStore() != null ? obj.getStore().getWorkspace() != null ? obj.getStore().getWorkspace().getName() : "" : ""); source.setNativeName(obj.getNativeName()); source.setStore(obj.getStore() != null ? obj.getStore().getName() : ""); if (obj.getNativeBoundingBox() != null) { source.setGeographicBunds(new Bounds(obj.getNativeBoundingBox())); } if (obj.boundingBox() != null) { source.setBounds(new Bounds(obj.boundingBox())); } } message.setSource(source); } if (notification.getObject() instanceof StoreInfo) { StoreInfo obj = (StoreInfo) notification.getObject(); KombuStoreInfo source = new KombuStoreInfo(); source.setId(obj.getId()); source.setType("StoreInfo"); source.setName(obj.getName()); source.setWorkspace(obj.getWorkspace() != null ? obj.getWorkspace().getName() : ""); message.setSource(source); } ret = mapper.writeValueAsBytes(message); return ret; }
From source file:org.openrepose.powerfilter.PowerFilterChain.java
private String convertPojoToJsonString(Object object) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); //http://stackoverflow.com/a/8395924 return objectMapper.writeValueAsString(object); }
From source file:org.verdictdb.core.scrambling.ScrambleMeta.java
public String toJsonString() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); String jsonString;/*from w ww. j a v a 2s . com*/ try { jsonString = objectMapper.writeValueAsString(this); return jsonString; } catch (JsonProcessingException e) { e.printStackTrace(); return null; } }
From source file:org.verdictdb.core.scrambling.ScrambleMeta.java
public static ScrambleMeta fromJsonString(String jsonString) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); try {// w w w .j a v a 2 s. c o m ScrambleMeta meta = objectMapper.readValue(jsonString, ScrambleMeta.class); return meta; } catch (IOException e) { e.printStackTrace(); return null; } }