com.fasterxml.jackson.databind.introspect.VisibilityChecker Java Examples
The following examples show how to use
com.fasterxml.jackson.databind.introspect.VisibilityChecker.
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: FailedItemMarshaller.java From log4j2-elasticsearch with Apache License 2.0 | 6 votes |
ObjectMapper createConfiguredObjectMapper() { return new ExtendedObjectMapper(new JsonFactory()) .setSerializationInclusion(JsonInclude.Include.NON_EMPTY) .configure(SerializationFeature.CLOSE_CLOSEABLE, false) .addMixIn(FailedItemInfo.class, FailedItemInfoMixIn.class) .addMixIn(ItemSource.class, ItemSourceMixIn.class) .addMixIn(FailedItemSource.class, FailedItemSourceDelegateMixIn.class) .addMixIn(ByteBufItemSource.class, ByteBufItemSourceMixIn.class) .addMixIn(StringItemSource.class, StringItemSourceMixIn.class) .addMixIn(ByteBuf.class, CompositeByteBufMixIn.class) .addMixIn(KeySequenceConfigKeys.class, KeySequenceConfigKeysMixIn.class) .addMixIn(KeySequenceConfig.class, KeySequenceConfigMixIn.class) .setInjectableValues(new InjectableValues.Std() .addValue("releaseCallback", (ReleaseCallback<ByteBuf>) source -> source.getSource().release())) .setVisibility(VisibilityChecker.Std.defaultInstance() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); }
Example #2
Source File: MapperConfigBase.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public final VisibilityChecker<?> getDefaultVisibilityChecker() { VisibilityChecker<?> vchecker = _configOverrides.getDefaultVisibility(); // then global overrides (disabling) // 05-Mar-2018, tatu: As per [databind#1947], need to see if any disabled if ((_mapperFeatures & AUTO_DETECT_MASK) != AUTO_DETECT_MASK) { if (!isEnabled(MapperFeature.AUTO_DETECT_FIELDS)) { vchecker = vchecker.withFieldVisibility(Visibility.NONE); } if (!isEnabled(MapperFeature.AUTO_DETECT_GETTERS)) { vchecker = vchecker.withGetterVisibility(Visibility.NONE); } if (!isEnabled(MapperFeature.AUTO_DETECT_IS_GETTERS)) { vchecker = vchecker.withIsGetterVisibility(Visibility.NONE); } if (!isEnabled(MapperFeature.AUTO_DETECT_SETTERS)) { vchecker = vchecker.withSetterVisibility(Visibility.NONE); } if (!isEnabled(MapperFeature.AUTO_DETECT_CREATORS)) { vchecker = vchecker.withCreatorVisibility(Visibility.NONE); } } return vchecker; }
Example #3
Source File: HttpMethodResponse.java From nexus3-keycloak-plugin with Apache License 2.0 | 6 votes |
public HttpMethodResponse<R> json(final TypeReference<R> responseType) { return new HttpMethodResponse<R>(this.method) { @Override public R execute() { return method.execute((InputStream inputStream) -> { try { JsonSerialization.mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); JsonSerialization.mapper.setVisibility(VisibilityChecker.Std.defaultInstance().withFieldVisibility(JsonAutoDetect.Visibility.ANY)); return JsonSerialization.readValue(inputStream, responseType); } catch (IOException e) { throw new RuntimeException("Error parsing JSON response.", e); } }); } }; }
Example #4
Source File: ConfigOverrides.java From lams with GNU General Public License v2.0 | 5 votes |
public ConfigOverrides() { this(null, // !!! TODO: change to (ALWAYS, ALWAYS)? JsonInclude.Value.empty(), JsonSetter.Value.empty(), VisibilityChecker.Std.defaultInstance(), null ); }
Example #5
Source File: JSONMapper.java From core-ng-project with Apache License 2.0 | 5 votes |
private static ObjectMapper createObjectMapper() { return JsonMapper.builder() .addModule(timeModule()) // disable value class loader to avoid jdk illegal reflection warning, requires JSON class/fields must be public .addModule(new AfterburnerModule().setUseValueClassLoader(false)) .defaultDateFormat(new StdDateFormat()) // only auto detect field, and default visibility is public_only, refer to com.fasterxml.jackson.databind.introspect.VisibilityChecker.Std .visibility(new VisibilityChecker.Std(NONE, NONE, NONE, NONE, PUBLIC_ONLY)) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .annotationIntrospector(new JSONAnnotationIntrospector()) .deactivateDefaultTyping() .build(); }
Example #6
Source File: BatchRequestResultDeserializerTest.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
@Test public void canDeserializeItems() throws IOException { // given ObjectMapper mapper = new ObjectMapper() .setSerializationInclusion(JsonInclude.Include.NON_NULL) .setVisibility(VisibilityChecker.Std.defaultInstance() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)) .addMixIn(BatchResult.class, BatchResultMixIn.class); String expectedId = UUID.randomUUID().toString(); String expectedIndex = UUID.randomUUID().toString(); String expectedType = UUID.randomUUID().toString(); int expectedStatus = random.nextInt(1000) + 1; BatchItemResult item = new BatchItemResult(); item.setId(expectedId); item.setIndex(expectedIndex); item.setType(expectedType); item.setStatus(expectedStatus); List<BatchItemResult> items = new ArrayList<>(); items.add(item); BatchResult batchResult = new BatchResult(0, true, null, 0, items); String json = mapper.writeValueAsString(batchResult); // when BatchResult result = mapper.readerFor(BatchResult.class).readValue(json); // then assertEquals(1, result.getItems().size()); BatchItemResult resultItem = result.getItems().get(0); assertEquals(resultItem.getId(), expectedId); assertEquals(resultItem.getIndex(), expectedIndex); assertEquals(resultItem.getStatus(), expectedStatus); assertEquals(resultItem.getType(), expectedType); }
Example #7
Source File: HCHttp.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
/** * @return {@code com.fasterxml.jackson.databind.ObjectReader} to deserialize {@link BatchResult} */ protected ObjectReader configuredReader() { return new ObjectMapper() .setVisibility(VisibilityChecker.Std.defaultInstance().with(JsonAutoDetect.Visibility.ANY)) .setSerializationInclusion(JsonInclude.Include.NON_EMPTY) .configure(SerializationFeature.CLOSE_CLOSEABLE, false) .configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true) .addMixIn(BatchResult.class, BatchResultMixIn.class) .addMixIn(Error.class, ErrorMixIn.class) .addMixIn(BatchItemResult.class, BatchItemResultMixIn.class) .readerFor(BatchResult.class); }
Example #8
Source File: BulkResultDeserializerTest.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
@Test public void canDeserializeItems() throws IOException { // given ObjectMapper mapper = new ObjectMapper() .setSerializationInclusion(JsonInclude.Include.NON_NULL) .setVisibility(VisibilityChecker.Std.defaultInstance() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)) .addMixIn(BufferedBulkResult.class, BufferedBulkResultMixIn.class); String expectedId = UUID.randomUUID().toString(); String expectedIndex = UUID.randomUUID().toString(); String expectedType = UUID.randomUUID().toString(); int expectedStatus = random.nextInt(1000) + 1; BulkResultItem item = new BulkResultItem(); item.setId(expectedId); item.setIndex(expectedIndex); item.setType(expectedType); item.setStatus(expectedStatus); List<BulkResultItem> items = new ArrayList<>(); items.add(item); BufferedBulkResult bufferedBulkResult = new BufferedBulkResult(0, true, null, 0, items); String json = mapper.writeValueAsString(bufferedBulkResult); // when BufferedBulkResult result = mapper.readerFor(BufferedBulkResult.class).readValue(json); // then assertEquals(1, result.getItems().size()); BulkResultItem resultItem = result.getItems().get(0); assertEquals(resultItem.getId(), expectedId); assertEquals(resultItem.getIndex(), expectedIndex); assertEquals(resultItem.getStatus(), expectedStatus); assertEquals(resultItem.getType(), expectedType); }
Example #9
Source File: BufferedBulkOperations.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
/** * @return {@code com.fasterxml.jackson.databind.ObjectReader} to deserialize {@link BufferedBulkResult} */ protected ObjectReader configuredReader() { return new ObjectMapper() .setVisibility(VisibilityChecker.Std.defaultInstance().with(JsonAutoDetect.Visibility.ANY)) .setSerializationInclusion(JsonInclude.Include.NON_EMPTY) .configure(SerializationFeature.CLOSE_CLOSEABLE, false) .configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true) .addMixIn(BufferedBulkResult.class, BufferedBulkResultMixIn.class) .addMixIn(BulkError.class, BulkErrorMixIn.class) .addMixIn(BulkResultItem.class, BulkResultItemMixIn.class) .readerFor(BufferedBulkResult.class); }
Example #10
Source File: MapperConfigBase.java From lams with GNU General Public License v2.0 | 5 votes |
@Override // since 2.9 public final VisibilityChecker<?> getDefaultVisibilityChecker(Class<?> baseType, AnnotatedClass actualClass) { VisibilityChecker<?> vc = getDefaultVisibilityChecker(); AnnotationIntrospector intr = getAnnotationIntrospector(); if (intr != null) { vc = intr.findAutoDetectVisibility(actualClass, vc); } ConfigOverride overrides = _configOverrides.findOverride(baseType); if (overrides != null) { vc = vc.withOverrides(overrides.getVisibility()); // ok to pass null } return vc; }
Example #11
Source File: ConfigOverrides.java From lams with GNU General Public License v2.0 | 5 votes |
protected ConfigOverrides(Map<Class<?>, MutableConfigOverride> overrides, JsonInclude.Value defIncl, JsonSetter.Value defSetter, VisibilityChecker<?> defVisibility, Boolean defMergeable) { _overrides = overrides; _defaultInclusion = defIncl; _defaultSetterInfo = defSetter; _visibilityChecker = defVisibility; _defaultMergeable = defMergeable; }
Example #12
Source File: CustomMessageFactoryTest.java From log4j2-elasticsearch with Apache License 2.0 | 4 votes |
private ObjectMapper configuredMapper() { return new ObjectMapper() .setSerializationInclusion(JsonInclude.Include.NON_EMPTY) .setVisibility(VisibilityChecker.Std.defaultInstance() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); }
Example #13
Source File: ConfigOverrides.java From lams with GNU General Public License v2.0 | 4 votes |
/** * @since 2.9 */ public void setDefaultVisibility(VisibilityChecker<?> v) { _visibilityChecker = v; }
Example #14
Source File: ConfigOverrides.java From lams with GNU General Public License v2.0 | 4 votes |
/** * @since 2.9 */ public VisibilityChecker<?> getDefaultVisibility() { return _visibilityChecker; }
Example #15
Source File: CustomMessageFactoryTest.java From log4j2-elasticsearch with Apache License 2.0 | 4 votes |
private ObjectMapper configuredMapper() { return new ObjectMapper() .setSerializationInclusion(JsonInclude.Include.NON_EMPTY) .setVisibility(VisibilityChecker.Std.defaultInstance() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); }
Example #16
Source File: ApiAnnotationIntrospector.java From endpoints-java with Apache License 2.0 | 4 votes |
@Override public VisibilityChecker<?> findAutoDetectVisibility( AnnotatedClass ac, VisibilityChecker<?> checker) { return checker.withSetterVisibility(Visibility.PUBLIC_ONLY); }
Example #17
Source File: Serializers.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
private static VisibilityChecker<?> fieldsOnlyVisibilityChecker(ObjectMapper mapper) { return mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE); }
Example #18
Source File: PossiblyStrictPreferringFieldsVisibilityChecker.java From brooklyn-server with Apache License 2.0 | 4 votes |
protected VisibilityChecker<?> viz() { return BidiSerialization.isStrictSerialization() ? vizStrict : vizDefault; }
Example #19
Source File: MapperConfig.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Accessor for object used for determining whether specific property elements * (method, constructors, fields) can be auto-detected based on * their visibility (access modifiers). This is based on global defaults * (as would be returned by {@link #getDefaultVisibilityChecker()}, but * then modified by possible class annotation (see {@link JsonAutoDetect}) * and/or per-type config override (see {@link ConfigOverride#getVisibility()}). * * @since 2.9 */ public abstract VisibilityChecker<?> getDefaultVisibilityChecker(Class<?> baseType, AnnotatedClass actualClass);
Example #20
Source File: MapperConfig.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Accessor for object used for determining whether specific property elements * (method, constructors, fields) can be auto-detected based on * their visibility (access modifiers). Can be changed to allow * different minimum visibility levels for auto-detection. Note * that this is the global handler; individual types (classes) * can further override active checker used (using * {@link JsonAutoDetect} annotation) */ public abstract VisibilityChecker<?> getDefaultVisibilityChecker();