javax.json.bind.config.PropertyVisibilityStrategy Java Examples

The following examples show how to use javax.json.bind.config.PropertyVisibilityStrategy. 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: MyJsonBContextResolver.java    From microprofile-rest-client with Apache License 2.0 6 votes vote down vote up
@Override
public Jsonb getContext(Class<?> type) {
    JsonbConfig config = new JsonbConfig().
            withPropertyVisibilityStrategy(new PropertyVisibilityStrategy(){

                @Override
                public boolean isVisible(Field f) {
                    return true;
                }

                @Override
                public boolean isVisible(Method m) {
                    return false;
                }
            });
    return JsonbBuilder.newBuilder().
            withConfig(config).
            build();
}
 
Example #2
Source File: JsonBindingExample.java    From Java-EE-8-Sampler with MIT License 5 votes vote down vote up
public String allCustomizedMapping() {

        PropertyVisibilityStrategy vis = new PropertyVisibilityStrategy() {
            @Override
            public boolean isVisible(Field field) {
                return false;
            }

            @Override
            public boolean isVisible(Method method) {
                return false;
            }
        };

        JsonbConfig jsonbConfig = new JsonbConfig()
                .withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_DASHES)
                .withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL)
                .withPropertyVisibilityStrategy(vis)
                .withStrictIJSON(true)
                .withFormatting(true)
                .withNullValues(true)
                .withBinaryDataStrategy(BinaryDataStrategy.BASE_64_URL)
                .withDateFormat("MM/dd/yyyy", Locale.ENGLISH);

        Jsonb jsonb = JsonbBuilder.create(jsonbConfig);

        return jsonb.toJson(book1);
    }
 
Example #3
Source File: JsonbParser.java    From typescript-generator with MIT License 5 votes vote down vote up
private JsonbPropertyExtractor(
        final Class<? extends Annotation> johnzonAny,
        final PropertyNamingStrategy propertyNamingStrategy,
        final PropertyVisibilityStrategy visibilityStrategy,
        final BaseAccessMode delegate) {
    this.johnzonAny = johnzonAny;
    this.naming = propertyNamingStrategy;
    this.visibility = visibilityStrategy;
    this.delegate = delegate;
}
 
Example #4
Source File: JsonbParser.java    From typescript-generator with MIT License 5 votes vote down vote up
private boolean isTransient(final JsonbParser.DecoratedType dt, final PropertyVisibilityStrategy visibility) {
    if (!FieldAndMethodAccessMode.CompositeDecoratedType.class.isInstance(dt)) {
        return isTransient(dt) || shouldSkip(visibility, dt);
    }
    final FieldAndMethodAccessMode.CompositeDecoratedType<?> cdt = FieldAndMethodAccessMode.CompositeDecoratedType.class.cast(dt);
    return isTransient(cdt.getType1()) || isTransient(cdt.getType2()) ||
            (shouldSkip(visibility, cdt.getType1()) && shouldSkip(visibility, cdt.getType2()));
}
 
Example #5
Source File: JsonbParser.java    From typescript-generator with MIT License 5 votes vote down vote up
@Override
public boolean isVisible(final Field field) {
    if (field.getAnnotation(JsonbProperty.class) != null) {
        return true;
    }
    final PropertyVisibilityStrategy strategy = strategies.computeIfAbsent(
            field.getDeclaringClass(), this::visibilityStrategy);
    return strategy == this ? Modifier.isPublic(field.getModifiers()) : strategy.isVisible(field);
}
 
Example #6
Source File: JsonbParser.java    From typescript-generator with MIT License 4 votes vote down vote up
private boolean shouldSkip(final PropertyVisibilityStrategy visibility, final JsonbParser.DecoratedType t) {
    return isNotVisible(visibility, t);
}
 
Example #7
Source File: JsonbParser.java    From typescript-generator with MIT License 4 votes vote down vote up
private boolean isNotVisible(final PropertyVisibilityStrategy visibility, final JsonbParser.DecoratedType t) {
    return !(JsonbParser.FieldAccessMode.FieldDecoratedType.class.isInstance(t) ?
            visibility.isVisible(JsonbParser.FieldAccessMode.FieldDecoratedType.class.cast(t).getField())
            : (MethodAccessMode.MethodDecoratedType.class.isInstance(t) &&
            visibility.isVisible(MethodAccessMode.MethodDecoratedType.class.cast(t).getMethod())));
}
 
Example #8
Source File: JsonbParser.java    From typescript-generator with MIT License 4 votes vote down vote up
@Override
public boolean isVisible(final Method method) {
    final PropertyVisibilityStrategy strategy = strategies.computeIfAbsent(
            method.getDeclaringClass(), this::visibilityStrategy);
    return strategy == this ? Modifier.isPublic(method.getModifiers()) : strategy.isVisible(method);
}