Java Code Examples for com.fasterxml.jackson.databind.ObjectMapper#setVisibilityChecker()
The following examples show how to use
com.fasterxml.jackson.databind.ObjectMapper#setVisibilityChecker() .
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: BrooklynObjectsJsonMapper.java From brooklyn-server with Apache License 2.0 | 6 votes |
public static ObjectMapper newMapper(ManagementContext mgmt) { ConfigurableSerializerProvider sp = new ConfigurableSerializerProvider(); sp.setUnknownTypeSerializer(new ErrorAndToStringUnknownTypeSerializer()); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializerProvider(sp); mapper.setVisibilityChecker(new PossiblyStrictPreferringFieldsVisibilityChecker()); SimpleModule mapperModule = new SimpleModule("Brooklyn", new Version(0, 0, 0, "ignored", null, null)); new BidiSerialization.ManagementContextSerialization(mgmt).install(mapperModule); new BidiSerialization.EntitySerialization(mgmt).install(mapperModule); new BidiSerialization.LocationSerialization(mgmt).install(mapperModule); new BidiSerialization.PolicySerialization(mgmt).install(mapperModule); new BidiSerialization.EnricherSerialization(mgmt).install(mapperModule); new BidiSerialization.FeedSerialization(mgmt).install(mapperModule); new BidiSerialization.TaskSerialization(mgmt).install(mapperModule); new BidiSerialization.ClassLoaderSerialization(mgmt).install(mapperModule); mapperModule.addSerializer(Duration.class, new DurationSerializer()); mapperModule.addSerializer(new MultimapSerializer()); mapper.registerModule(mapperModule); return mapper; }
Example 2
Source File: JacksonConverterFactoryTest.java From jus with Apache License 2.0 | 6 votes |
@Before public void setUp() { queue = Jus.newRequestQueue(); SimpleModule module = new SimpleModule(); module.addSerializer(AnInterface.class, new AnInterfaceSerializer()); module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer()); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(module); mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false); mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false); mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false); mapper.setVisibilityChecker(mapper.getSerializationConfig() .getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); RetroProxy retroProxy = new RetroProxy.Builder() .baseUrl(server.url("/").toString()) .addConverterFactory(JacksonConverterFactory.create(mapper)) .requestQueue(queue) .build(); service = retroProxy.create(Service.class); }
Example 3
Source File: JacksonRequestTest.java From jus with Apache License 2.0 | 6 votes |
@Before public void setUp() { queue = Jus.newRequestQueue(); SimpleModule module = new SimpleModule(); module.addSerializer(AnInterface.class, new AnInterfaceSerializer()); module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer()); mapper = new ObjectMapper(); mapper.registerModule(module); mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false); mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false); mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false); mapper.setVisibilityChecker(mapper.getSerializationConfig() .getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); }
Example 4
Source File: Serializers.java From gsc-core with GNU Lesser General Public License v3.0 | 5 votes |
public static String serializeFieldsOnly(Object value, boolean pretty) { try { ObjectMapper mapper = createMapper(pretty); mapper.setVisibilityChecker(fieldsOnlyVisibilityChecker(mapper)); return mapper.writeValueAsString(value); } catch (Exception e) { logger.error("JSON serialization error: ", e); return "{}"; } }
Example 5
Source File: TestJsonAfterUnmarshal.java From vethrfolnir-mu with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws Exception { ArrayList<TestThing> tsts = new ArrayList<>(); for (int i = 0; i < 21; i++) { final int nr = i; tsts.add(new TestThing() { { id = 1028 * nr + 256; name = "Name-"+nr; } }); } ObjectMapper mp = new ObjectMapper(); mp.setVisibilityChecker(mp.getDeserializationConfig().getDefaultVisibilityChecker() .withCreatorVisibility(JsonAutoDetect.Visibility.NONE) .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE)); mp.configure(SerializationFeature.INDENT_OUTPUT, true); ByteArrayOutputStream br = new ByteArrayOutputStream(); mp.writeValue(System.err, tsts); mp.writeValue(br, tsts); ByteArrayInputStream in = new ByteArrayInputStream(br.toByteArray()); tsts = mp.readValue(in, new TypeReference<ArrayList<TestThing>>() {}); System.err.println(); System.out.println("Got: "+tsts); }