com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder Java Examples

The following examples show how to use com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder. 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: DTOContractTest.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static Optional<Constructor<?>> getConstructorHavingJsonBuilder(Class<?> clazz) {
    for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
        final List<Class<?>> parameterTypes = Arrays.stream(constructor.getParameterTypes())
                .filter(s -> s.getName().contains("Builder")).collect(Collectors.toList());

        if (parameterTypes.size() > 0) {
            final Annotation[] annotations = parameterTypes.get(0).getAnnotations();

            for (Annotation annotation : annotations) {
                if (annotation.annotationType() == JsonPOJOBuilder.class) {
                    return Optional.of(constructor);
                }
            }
        }
    }
    return Optional.empty();
}
 
Example #2
Source File: AptDeserializerBuilder.java    From domino-jackson with Apache License 2.0 5 votes vote down vote up
private MethodSpec newInstanceMethod(TypeMirror beanType, MethodSpec createMethod, boolean useBuilder) {
    MethodSpec.Builder builder = MethodSpec.methodBuilder("newInstance")
            .addModifiers(Modifier.PUBLIC)
            .addAnnotation(Override.class)
            .returns(ParameterizedTypeName.get(ClassName.get(Instance.class), ClassName.get(beanType)))
            .addParameter(JsonReader.class, "reader")
            .addParameter(JsonDeserializationContext.class, "ctx")
            .addParameter(JsonDeserializerParameters.class, "params")
            .addParameter(ParameterizedTypeName.get(Map.class, String.class, String.class), "bufferedProperties")
            .addParameter(ParameterizedTypeName.get(Map.class, String.class, Object.class), "bufferedPropertiesValues");

    if (useBuilder) {
        TypeElement builderElement = getBuilderElement();
        JsonPOJOBuilder jsonPOJOBuilder = builderElement.getAnnotation(JsonPOJOBuilder.class);
        String buildMethodName = JsonPOJOBuilder.DEFAULT_BUILD_METHOD;
        if (nonNull(jsonPOJOBuilder)) {
            buildMethodName = jsonPOJOBuilder.buildMethodName();
        }
        builder.addStatement("return new $T(builderDeserializer.deserializeInline(reader, ctx, params, null, null, null, bufferedProperties)." + buildMethodName + "(), bufferedProperties)",
                ParameterizedTypeName.get(ClassName.get(Instance.class), ClassName.get(beanType)));
    } else if (isUseJsonCreator()) {
        buildAssignProperties(beanType, createMethod, builder);
    } else {
        builder.addStatement("return new $T($N(), bufferedProperties)",
                ParameterizedTypeName.get(ClassName.get(Instance.class), ClassName.get(beanType)),
                createMethod);
    }

    return builder.build();
}
 
Example #3
Source File: BasicClassIntrospector.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> config,
        JavaType type, MixInResolver r, boolean forSerialization)
{
    AnnotatedClass ac = _resolveAnnotatedClass(config, type, r);
    AnnotationIntrospector ai = config.isAnnotationProcessingEnabled() ? config.getAnnotationIntrospector() : null;
    JsonPOJOBuilder.Value builderConfig = (ai == null) ? null : ai.findPOJOBuilderConfig(ac);
    String mutatorPrefix = (builderConfig == null) ? JsonPOJOBuilder.DEFAULT_WITH_PREFIX : builderConfig.withPrefix;
    return constructPropertyCollector(config, ac, type, forSerialization, mutatorPrefix);
}
 
Example #4
Source File: BasicBeanDescription.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public JsonPOJOBuilder.Value findPOJOBuilderConfig()
{
    return (_annotationIntrospector == null) ?
            null : _annotationIntrospector.findPOJOBuilderConfig(_classInfo);
}
 
Example #5
Source File: AnnotationIntrospectorPair.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public JsonPOJOBuilder.Value findPOJOBuilderConfig(AnnotatedClass ac) {
    JsonPOJOBuilder.Value result = _primary.findPOJOBuilderConfig(ac);
    return (result == null) ? _secondary.findPOJOBuilderConfig(ac) : result;
}
 
Example #6
Source File: BeanDeserializerBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void setPOJOBuilder(AnnotatedMethod buildMethod, JsonPOJOBuilder.Value config) {
    _buildMethod = buildMethod;
    _builderConfig = config;
}
 
Example #7
Source File: BeanDeserializerBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public JsonPOJOBuilder.Value getBuilderConfig() {
    return _builderConfig;
}
 
Example #8
Source File: AnnotationIntrospector.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.0
 */
public JsonPOJOBuilder.Value findPOJOBuilderConfig(AnnotatedClass ac) {
    return null;
}
 
Example #9
Source File: BeanDescription.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Method for finding configuration for POJO Builder class.
 */
public abstract JsonPOJOBuilder.Value findPOJOBuilderConfig();