Java Code Examples for com.fasterxml.jackson.databind.SerializationConfig

The following are top voted examples for showing how to use com.fasterxml.jackson.databind.SerializationConfig. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: aws-xray-sdk-java   File: EntityImpl.java   Source Code and License 8 votes vote down vote up
@Override
public void setupModule(SetupContext setupContext) {
    super.setupModule(setupContext);
    setupContext.addBeanSerializerModifier(new BeanSerializerModifier() {
        @SuppressWarnings("unchecked")
        @Override
        public JsonSerializer<?> modifySerializer(SerializationConfig serializationConfig, BeanDescription beanDescription, JsonSerializer<?> jsonSerializer) {
            Class<?> beanClass = beanDescription.getBeanClass();
            if (Cause.class.isAssignableFrom(beanClass)) {
                return new CauseSerializer((JsonSerializer<Object>) jsonSerializer);
            } else if (StackTraceElement.class.isAssignableFrom(beanClass)) {
                return new StackTraceElementSerializer();
            }
            return jsonSerializer;
        }
    });
}
 
Example 2
Project: eservice   File: CommonBeans.java   Source Code and License 7 votes vote down vote up
@Bean(name = "objectMapper")
public ObjectMapper getObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();

    mapper.registerModule(new GuavaModule());
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new JodaModule());
    mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
        // borrowed from: http://jackson-users.ning.com/forum/topics/how-to-not-include-type-info-during-serialization-with
        @Override
        protected TypeResolverBuilder<?> _findTypeResolver(MapperConfig<?> config, Annotated ann, JavaType baseType) {

            // Don't serialize JsonTypeInfo Property includes
            if (ann.hasAnnotation(JsonTypeInfo.class)
                    && ann.getAnnotation(JsonTypeInfo.class).include() == JsonTypeInfo.As.PROPERTY
                    && SerializationConfig.class.isAssignableFrom(config.getClass())) {
                return null;

            }

            return super._findTypeResolver(config, ann, baseType);
        }
    });

    return mapper;
}
 
Example 3
Project: crnk-framework   File: AnnotatedClassBuilder.java   Source Code and License 6 votes vote down vote up
public static AnnotatedClass build(final Class<?> declaringClass, final SerializationConfig serializationConfig) {

		for (final Method method : AnnotatedClass.class.getMethods()) {
			if (CONSTRUCT_METHOD_NAME.equals(method.getName()) &&
					method.getParameterTypes().length == 3) {

				return ExceptionUtil.wrapCatchedExceptions(new Callable<AnnotatedClass>() {
					@Override
					public AnnotatedClass call() throws Exception {
						return buildAnnotatedClass(method, declaringClass, serializationConfig);
					}
				}, "Exception while building AnnotatedClass");
			}
		}
		throw new IllegalStateException(CANNOT_FIND_PROPER_METHOD);
	}
 
Example 4
Project: crnk-framework   File: JacksonResourceFieldInformationProvider.java   Source Code and License 6 votes vote down vote up
protected Optional<String> getName(Method method) {
	ObjectMapper objectMapper = context.getObjectMapper();
	SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
	if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
		String name = ClassUtils.getGetterFieldName(method);
		Annotation[] declaredAnnotations = method.getDeclaredAnnotations();
		AnnotationMap annotationMap = buildAnnotationMap(declaredAnnotations);

		int paramsLength = method.getParameterAnnotations().length;
		AnnotationMap[] paramAnnotations = new AnnotationMap[paramsLength];
		for (int i = 0; i < paramsLength; i++) {
			AnnotationMap parameterAnnotationMap = buildAnnotationMap(method.getParameterAnnotations()[i]);
			paramAnnotations[i] = parameterAnnotationMap;
		}

		AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(method.getDeclaringClass(), serializationConfig);
		AnnotatedMethod annotatedField = AnnotatedMethodBuilder.build(annotatedClass, method, annotationMap, paramAnnotations);
		return Optional.of(serializationConfig.getPropertyNamingStrategy().nameForGetterMethod(serializationConfig, annotatedField, name));
	}
	return Optional.empty();
}
 
Example 5
Project: jddd   File: SimpleValueObjectSerializerModifier.java   Source Code and License 6 votes vote down vote up
@Override
public BeanSerializerBuilder updateBuilder(SerializationConfig config, BeanDescription beanDesc,
		BeanSerializerBuilder builder) {

	for (BeanPropertyWriter writer : builder.getProperties()) {

		JavaType propertyType = writer.getMember().getType();
		Class<?> type = propertyType.getRawClass();
		List<BeanPropertyDefinition> properties = getProperties(propertyType, config);

		Optional.ofNullable(AnnotationUtils.findAnnotation(type, ValueObject.class))//
				.filter(it -> properties.size() == 1)//
				.flatMap(it -> properties.stream().findFirst())//
				.ifPresent(it -> writer.assignSerializer(new PropertyAccessingSerializer(it)));
	}

	return builder;
}
 
Example 6
Project: java-triton   File: PostprocessModificationModule.java   Source Code and License 6 votes vote down vote up
@Override
public void setupModule(final SetupContext context) {
    super.setupModule(context);

    context.addBeanSerializerModifier(new BeanSerializerModifier() {

        public JsonSerializer<?> modifySerializer(
                final SerializationConfig config,
                final BeanDescription beanDesc,
                final JsonSerializer<?> serializer) {
            Class<?> valueClass = beanDesc.getType().getRawClass();

            if (serializer instanceof BeanSerializerBase
                    && MODIFIABLE_CLASSES.contains(valueClass)) {
                return new FlatteningModifySerializer(
                        (BeanSerializerBase) serializer);
            }

            return serializer;
        }
    });
}
 
Example 7
Project: bowman   File: JacksonClientModule.java   Source Code and License 6 votes vote down vote up
public JacksonClientModule() {
	setSerializerModifier(new BeanSerializerModifier() {

		@Override
		public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc,
				List<BeanPropertyWriter> beanProperties) {
			
			for (BeanPropertyWriter writer : beanProperties) {
				if (writer.getAnnotation(LinkedResource.class) != null) {
					writer.assignSerializer(new LinkedResourceUriSerializer());
				}
			}
			
			return beanProperties;
		}
	});
	
	setMixInAnnotation(Resource.class, ResourceMixin.class);
}
 
Example 8
Project: aem-core-wcm-components   File: DefaultMethodSkippingModuleProvider.java   Source Code and License 6 votes vote down vote up
public DefaultMethodSkippingModuleProvider() {
    module = new SimpleModule();
    module.setSerializerModifier(new BeanSerializerModifier() {
        @Override
        public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {

            return super.changeProperties(config, beanDesc, beanProperties.stream().filter(bpw -> {
                final AnnotatedMember jacksonMember = bpw.getMember();
                final Member member = jacksonMember.getMember();
                if (member instanceof Method) {
                    final Method method = (Method) member;
                    if (method.isDefault()) {
                        // only exclude default methods if they are defined on interfaces from the core components
                        return !method.getDeclaringClass().getName().startsWith(PACKAGE_CORE_COMPONENTS);
                    }
                }
                return true;
            }).collect(Collectors.toList()));
        }
    });
}
 
Example 9
Project: NyBatisCore   File: SerializerModifier.java   Source Code and License 6 votes vote down vote up
@Override
public JsonSerializer<?> modifySerializer( SerializationConfig config, BeanDescription beanDesc, JsonSerializer<?> serializer ) {

    Class<?> klass = beanDesc.getBeanClass();

    if( klass == Boolean.class ) {
        return new BooleanSerializer( serializer );
    } else if( klass == Integer.class ) {
        return new IntegerSerializer( serializer );
    } else if( klass == Long.class ) {
        return new LongSerializer( serializer );
    } else if( klass == Float.class ) {
        return new FloatSerializer( serializer );
    } else if( klass == Double.class ) {
        return new DoubleSerializer( serializer );
    } else if( klass == BigDecimal.class ) {
        return new BigDecimalSerializer( serializer );
    } else if( ClassUtil.isExtendedBy( klass, Date.class ) ) {
        return new DateSerializer( serializer );
    }

    return serializer;

}
 
Example 10
Project: eMonocot   File: HibernateSerializers.java   Source Code and License 6 votes vote down vote up
@Override
public JsonSerializer<?> findSerializer(
		SerializationConfig config, JavaType type,
		BeanDescription beanDesc)
		{
	Class<?> raw = type.getRawClass();

	/* Note: PersistentCollection does not implement Collection, so we
	 * may get some types here...
	 */
	if (PersistentCollection.class.isAssignableFrom(raw)) {
		// TODO: handle iterator types? Or PersistentArrayHolder?
	}

	if (HibernateProxy.class.isAssignableFrom(raw)) {
		return new HibernateProxySerializer(isEnabled(Feature.FORCE_LAZY_LOADING));
	}
	return null;
		}
 
Example 11
Project: eMonocot   File: HibernateSerializers.java   Source Code and License 6 votes vote down vote up
protected JavaType _figureFallbackType(SerializationConfig config,
		JavaType persistentType)
{
	// Alas, PersistentTypes are NOT generics-aware... meaning can't specify parameterization
	Class<?> raw = persistentType.getRawClass();
	TypeFactory tf = config.getTypeFactory();
	if (Map.class.isAssignableFrom(raw)) {
		return tf.constructMapType(Map.class, Object.class, Object.class);
	}
	if (List.class.isAssignableFrom(raw)) {
		return tf.constructCollectionType(List.class, Object.class);
	}
	if (Set.class.isAssignableFrom(raw)) {
		return tf.constructCollectionType(Set.class, Object.class);
	}
	// ok, just Collection of some kind
	return tf.constructCollectionType(Collection.class, Object.class);
}
 
Example 12
Project: logsniffer   File: CoreAppConfig.java   Source Code and License 6 votes vote down vote up
@Bean
public ObjectMapper jsonObjectMapper() {
	final ObjectMapper jsonMapper = new ObjectMapper();
	jsonMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
	jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	jsonMapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
	jsonMapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);
	jsonMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);

	final SimpleModule module = new SimpleModule("FieldsMapping", Version.unknownVersion());
	module.setSerializerModifier(new BeanSerializerModifier() {
		@Override
		public JsonSerializer<?> modifyMapSerializer(final SerializationConfig config, final MapType valueType,
				final BeanDescription beanDesc, final JsonSerializer<?> serializer) {
			if (FieldsMap.class.isAssignableFrom(valueType.getRawClass())) {
				return new FieldsMapMixInLikeSerializer();
			} else {
				return super.modifyMapSerializer(config, valueType, beanDesc, serializer);
			}
		}
	});
	jsonMapper.registerModule(module);
	return jsonMapper;
}
 
Example 13
Project: metadict   File: MetadictJacksonModule.java   Source Code and License 6 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
    super.setupModule(context);

    context.addBeanSerializerModifier(new BeanSerializerModifier() {

        public JsonSerializer<?> modifySerializer(
                SerializationConfig config,
                BeanDescription beanDesc,
                JsonSerializer<?> serializer) {
            if (serializer instanceof BeanSerializerBase) {
                return new DictionaryObjectSerializer(
                        (BeanSerializerBase) serializer);
            }
            return serializer;
        }
    });
}
 
Example 14
Project: vavr-jackson   File: VavrSerializers.java   Source Code and License 6 votes vote down vote up
@Override
public JsonSerializer<?> findCollectionLikeSerializer(SerializationConfig config,
                                                      CollectionLikeType type, BeanDescription beanDesc,
                                                      TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) {
    Class<?> raw = type.getRawClass();
    if (raw == CharSeq.class) {
        return new CharSeqSerializer(type);
    }
    if (Seq.class.isAssignableFrom(raw)) {
        return new ArraySerializer<>(type);
    }
    if (Set.class.isAssignableFrom(raw)) {
        return new ArraySerializer<>(type);
    }
    if (PriorityQueue.class.isAssignableFrom(raw)) {
        return new ArraySerializer<>(type);
    }
    return super.findCollectionLikeSerializer(config, type, beanDesc, elementTypeSerializer, elementValueSerializer);
}
 
Example 15
Project: QuizUpWinner   File: StdTypeResolverBuilder.java   Source Code and License 6 votes vote down vote up
public TypeSerializer buildTypeSerializer(SerializationConfig paramSerializationConfig, JavaType paramJavaType, Collection<NamedType> paramCollection)
{
  if (this._idType == JsonTypeInfo.Id.NONE)
    return null;
  TypeIdResolver localTypeIdResolver = idResolver(paramSerializationConfig, paramJavaType, paramCollection, true, false);
  switch (1.$SwitchMap$com$fasterxml$jackson$annotation$JsonTypeInfo$As[this._includeAs.ordinal()])
  {
  default:
    break;
  case 1:
    return new AsArrayTypeSerializer(localTypeIdResolver, null);
  case 2:
    return new AsPropertyTypeSerializer(localTypeIdResolver, null, this._typeProperty);
  case 3:
    return new AsWrapperTypeSerializer(localTypeIdResolver, null);
  case 4:
    return new AsExternalTypeSerializer(localTypeIdResolver, null, this._typeProperty);
  }
  throw new IllegalStateException("Do not know how to construct standard type serializer for inclusion type: " + this._includeAs);
}
 
Example 16
Project: QuizUpWinner   File: BeanSerializerFactory.java   Source Code and License 6 votes vote down vote up
protected void processViews(SerializationConfig paramSerializationConfig, BeanSerializerBuilder paramBeanSerializerBuilder)
{
  List localList = paramBeanSerializerBuilder.getProperties();
  boolean bool = paramSerializationConfig.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION);
  int i = localList.size();
  int j = 0;
  BeanPropertyWriter[] arrayOfBeanPropertyWriter = new BeanPropertyWriter[i];
  for (int k = 0; k < i; k++)
  {
    BeanPropertyWriter localBeanPropertyWriter = (BeanPropertyWriter)localList.get(k);
    Class[] arrayOfClass = localBeanPropertyWriter.getViews();
    if (arrayOfClass == null)
    {
      if (bool)
        arrayOfBeanPropertyWriter[k] = localBeanPropertyWriter;
    }
    else
    {
      j++;
      arrayOfBeanPropertyWriter[k] = constructFilteredBeanWriter(localBeanPropertyWriter, arrayOfClass);
    }
  }
  if ((bool) && (j == 0))
    return;
  paramBeanSerializerBuilder.setFilteredProperties(arrayOfBeanPropertyWriter);
}
 
Example 17
Project: QuizUpWinner   File: BasicSerializerFactory.java   Source Code and License 6 votes vote down vote up
protected JsonSerializer<?> buildEnumSerializer(SerializationConfig paramSerializationConfig, JavaType paramJavaType, BeanDescription paramBeanDescription)
{
  JsonFormat.Value localValue = paramBeanDescription.findExpectedFormat(null);
  if ((localValue != null) && (localValue.getShape() == JsonFormat.Shape.OBJECT))
  {
    ((BasicBeanDescription)paramBeanDescription).removeProperty("declaringClass");
    return null;
  }
  Object localObject = EnumSerializer.construct(paramJavaType.getRawClass(), paramSerializationConfig, paramBeanDescription, localValue);
  if (this._factoryConfig.hasSerializerModifiers())
  {
    Iterator localIterator = this._factoryConfig.serializerModifiers().iterator();
    while (localIterator.hasNext())
      localObject = ((BeanSerializerModifier)localIterator.next()).modifyEnumSerializer(paramSerializationConfig, paramJavaType, paramBeanDescription, (JsonSerializer)localObject);
  }
  return localObject;
}
 
Example 18
Project: QuizUpWinner   File: BasicSerializerFactory.java   Source Code and License 6 votes vote down vote up
public TypeSerializer createTypeSerializer(SerializationConfig paramSerializationConfig, JavaType paramJavaType)
{
  AnnotatedClass localAnnotatedClass = paramSerializationConfig.introspectClassAnnotations(paramJavaType.getRawClass()).getClassInfo();
  AnnotationIntrospector localAnnotationIntrospector = paramSerializationConfig.getAnnotationIntrospector();
  TypeResolverBuilder localTypeResolverBuilder = localAnnotationIntrospector.findTypeResolver(paramSerializationConfig, localAnnotatedClass, paramJavaType);
  Collection localCollection;
  if (localTypeResolverBuilder == null)
  {
    localTypeResolverBuilder = paramSerializationConfig.getDefaultTyper(paramJavaType);
    localCollection = null;
  }
  else
  {
    localCollection = paramSerializationConfig.getSubtypeResolver().collectAndResolveSubtypes(localAnnotatedClass, paramSerializationConfig, localAnnotationIntrospector);
  }
  if (localTypeResolverBuilder == null)
    return null;
  return localTypeResolverBuilder.buildTypeSerializer(paramSerializationConfig, paramJavaType, localCollection);
}
 
Example 19
Project: QuizUpWinner   File: BasicSerializerFactory.java   Source Code and License 6 votes vote down vote up
protected final JsonSerializer<?> findSerializerByLookup(JavaType paramJavaType, SerializationConfig paramSerializationConfig, BeanDescription paramBeanDescription, boolean paramBoolean)
{
  String str = paramJavaType.getRawClass().getName();
  JsonSerializer localJsonSerializer1 = (JsonSerializer)_concrete.get(str);
  if (localJsonSerializer1 == null)
  {
    Class localClass = (Class)_concreteLazy.get(str);
    if (localClass != null)
      try
      {
        JsonSerializer localJsonSerializer2 = (JsonSerializer)localClass.newInstance();
        return localJsonSerializer2;
      }
      catch (Exception localException)
      {
        throw new IllegalStateException("Failed to instantiate standard serializer (of type " + localClass.getName() + "): " + localException.getMessage(), localException);
      }
  }
  return localJsonSerializer1;
}
 
Example 20
Project: hydra-java   File: JacksonHydraModule.java   Source Code and License 6 votes vote down vote up
public void setupModule(SetupContext context) {
    super.setupModule(context);

    context.addBeanSerializerModifier(new BeanSerializerModifier() {

        public JsonSerializer<?> modifySerializer(
                SerializationConfig config,
                BeanDescription beanDesc,
                JsonSerializer<?> serializer) {

            if (serializer instanceof BeanSerializerBase) {
                JacksonHydraSerializer jacksonHydraSerializer = new JacksonHydraSerializer(
                        (BeanSerializerBase) serializer, proxyUnwrapper);
                return jacksonHydraSerializer;
            } else {
                return serializer;
            }
        }
    });
}
 
Example 21
Project: iiif-apis   File: SerializerModifier.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> modifyCollectionSerializer(SerializationConfig config, CollectionType valueType,
    BeanDescription beanDesc, JsonSerializer<?> serializer) {
  if (valueType.getRawClass() == ArrayList.class) {
    return new IiifIndexedListSerializer((IndexedListSerializer) serializer, config.getTypeFactory());
  }
  return super.modifyCollectionSerializer(config, valueType, beanDesc, serializer);
}
 
Example 22
Project: iiif-apis   File: SerializerModifier.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc,
    JsonSerializer<?> serializer) {
  if (Resource.class.isAssignableFrom(beanDesc.getBeanClass())) {
    return new ResourceSerializer((JsonSerializer<Object>) serializer);
  } else if (Profile.class.isAssignableFrom(beanDesc.getBeanClass())) {
    return new ProfileSerializer((JsonSerializer<Object>) serializer);
  }
  return super.modifySerializer(config, beanDesc, serializer);
}
 
Example 23
Project: crnk-framework   File: AnnotatedClassBuilder.java   Source Code and License 5 votes vote down vote up
private static AnnotatedClass buildAnnotatedClass(Method method, Class<?> declaringClass,
		SerializationConfig serializationConfig)
		throws InvocationTargetException, IllegalAccessException {
	if (method.getParameterTypes()[0] == Class.class) {
		return buildOldAnnotatedClass(method, declaringClass, serializationConfig);
	}
	else {
		PreconditionUtil.assertEquals("unexpected method signature", method.getParameterTypes()[0], JavaType.class);
		return buildNewAnnotatedClass(method, declaringClass, serializationConfig);
	}
}
 
Example 24
Project: crnk-framework   File: AnnotatedClassBuilder.java   Source Code and License 5 votes vote down vote up
private static AnnotatedClass buildOldAnnotatedClass(Method method, Class<?> declaringClass,
		SerializationConfig serializationConfig)
		throws InvocationTargetException, IllegalAccessException {
	boolean useAnnotations = serializationConfig.isAnnotationProcessingEnabled();
	AnnotationIntrospector aintr = useAnnotations ? serializationConfig.getAnnotationIntrospector() : null;
	return AnnotatedClass.class.cast(method.invoke(null, declaringClass, aintr, serializationConfig));
}
 
Example 25
Project: crnk-framework   File: JacksonResourceFieldInformationProvider.java   Source Code and License 5 votes vote down vote up
protected Optional<String> getName(Field field) {
	ObjectMapper objectMapper = context.getObjectMapper();
	SerializationConfig serializationConfig = objectMapper.getSerializationConfig();

	if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
		AnnotationMap annotationMap = buildAnnotationMap(field.getDeclaredAnnotations());

		AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(field.getDeclaringClass(), serializationConfig);
		AnnotatedField annotatedField = AnnotatedFieldBuilder.build(annotatedClass, field, annotationMap);
		return Optional.of(serializationConfig.getPropertyNamingStrategy().nameForField(serializationConfig, annotatedField, field.getName()));
	}
	return Optional.empty();
}
 
Example 26
Project: -deprecated-hlp-candidate   File: SupernodeModule.java   Source Code and License 5 votes vote down vote up
public SupernodeModule(Supplier<Boolean> production) {
    super("Supernode");

    this.formatter = HyperLedgerSettings.getInstance().getTxWireFormatter();

    addDeserializer(MasterPrivateKey.class, new MasterPrivateKeyDeserializer());
    addDeserializer(MasterPublicKey.class, new MasterPublicKeyDeserializer());
    addDeserializer(Script.class, new ScriptDeserializer());
    addDeserializer(UIAddress.class, new AddressDeserializer());
    addDeserializer(Transaction.class, new TransactionDeserializer(formatter));
    addDeserializer(Hash.class, new HashDeserializer());
    addDeserializer(TID.class, new TIDDeserializer());
    addDeserializer(BID.class, new BIDDeserializer());

    addSerializer(MasterPrivateKey.class, new MasterPrivateKeySerializer());
    addSerializer(MasterPublicKey.class, new MasterPublicKeySerializer());
    addSerializer(Script.class, new ScriptSerializer());
    addSerializer(UIAddress.class, new AddressSerializer());
    addSerializer(Transaction.class, new TransactionSerializer());
    addSerializer(Outpoint.class, new OutpointSerializer());
    addSerializer(Hash.class, new HashSerializer());
    addSerializer(TID.class, new TIDSerializer());
    addSerializer(BID.class, new BIDSerializer());

    this.setSerializerModifier(new BeanSerializerModifier() {
        @Override
        public JsonSerializer<?> modifySerializer(SerializationConfig config,
                                                  BeanDescription beanDesc,
                                                  JsonSerializer<?> serializer) {
            if (serializer instanceof MasterPublicKeySerializer) {
                MasterPublicKeySerializer.class.cast(serializer).setProduction(production.get());
            }
            if (serializer instanceof MasterPrivateKeySerializer) {
                MasterPrivateKeySerializer.class.cast(serializer).setProduction(production.get());
            }

            return serializer;
        }
    });
}
 
Example 27
Project: jb4jsonld-jackson   File: JsonLdSerializerModifier.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc,
                                          JsonSerializer<?> serializer) {
    if (BeanAnnotationProcessor.isOwlClassEntity(beanDesc.getBeanClass())) {
        return new JacksonJsonLdSerializer<>();
    }
    return serializer;
}
 
Example 28
Project: sam   File: JsonHelper.java   Source Code and License 5 votes vote down vote up
public static JsonSerializer<Object> getBeanSerializer(SerializerProvider sp, Class<?> cls) throws JsonMappingException {

    final SerializationConfig config = sp.getConfig();
    final JavaType type = config.constructType(cls);
    final BeanDescription beanDesc = config.introspect(type);
    return BeanSerializerFactory.instance.findBeanSerializer(sp, type, beanDesc);
  }
 
Example 29
Project: jacksonatic   File: JacksonaticInternal.java   Source Code and License 5 votes vote down vote up
private void registerForSerializationIn(ObjectMapper objectMapper) {
    SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
    ClassIntrospector classIntrospector = serializationConfig.getClassIntrospector();
    if (!(classIntrospector instanceof JacksonaticClassIntrospector)) {
        objectMapper.setConfig(serializationConfig.with(new JacksonaticClassIntrospector()));
    }
    JacksonaticClassIntrospector basicClassIntrospector = (JacksonaticClassIntrospector) objectMapper.getSerializationConfig().getClassIntrospector();
    basicClassIntrospector.register(this);
}
 
Example 30
Project: katharsis-framework   File: AnnotatedClassBuilder.java   Source Code and License 5 votes vote down vote up
public static AnnotatedClass build(Class<?> declaringClass, SerializationConfig serializationConfig) {

        for (Method method : AnnotatedClass.class.getMethods()) {
            if (CONSTRUCT_METHOD_NAME.equals(method.getName()) &&
                method.getParameterTypes().length == 3) {
                try {
                    return buildAnnotatedClass(method, declaringClass, serializationConfig);
                } catch (InvocationTargetException | IllegalAccessException e) {
                    throw new InternalException("Exception while building " + AnnotatedClass.class.getCanonicalName(), e);
                }
            }
        }

        throw new InternalException(CANNOT_FIND_PROPER_METHOD);
    }
 
Example 31
Project: katharsis-framework   File: AnnotatedClassBuilder.java   Source Code and License 5 votes vote down vote up
private static AnnotatedClass buildAnnotatedClass(Method method, Class<?> declaringClass,
                                                  SerializationConfig serializationConfig)
    throws InvocationTargetException, IllegalAccessException {
    if (method.getParameterTypes()[0] == Class.class) {
        return buildOldAnnotatedClass(method, declaringClass, serializationConfig);
    } else if (method.getParameterTypes()[0] == JavaType.class) {
        return buildNewAnnotatedClass(method, declaringClass, serializationConfig);
    } else {
        throw new InternalException(CANNOT_FIND_PROPER_METHOD);
    }
}
 
Example 32
Project: katharsis-framework   File: AnnotatedClassBuilder.java   Source Code and License 5 votes vote down vote up
private static AnnotatedClass buildOldAnnotatedClass(Method method, Class<?> declaringClass,
                                                     SerializationConfig serializationConfig)
    throws InvocationTargetException, IllegalAccessException {
    boolean useAnnotations = serializationConfig.isAnnotationProcessingEnabled();
    AnnotationIntrospector aintr = useAnnotations ? serializationConfig.getAnnotationIntrospector() : null;
    return AnnotatedClass.class.cast(method.invoke(null, declaringClass, aintr, serializationConfig));
}
 
Example 33
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: ConfigurationPropertiesReportEndpoint.java   Source Code and License 5 votes vote down vote up
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config,
		BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
	List<BeanPropertyWriter> result = new ArrayList<BeanPropertyWriter>();
	for (BeanPropertyWriter writer : beanProperties) {
		boolean readable = isReadable(beanDesc, writer);
		if (readable) {
			result.add(writer);
		}
	}
	return result;
}
 
Example 34
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: DataSourceJsonSerializationTests.java   Source Code and License 5 votes vote down vote up
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config,
		BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
	List<BeanPropertyWriter> result = new ArrayList<BeanPropertyWriter>();
	for (BeanPropertyWriter writer : beanProperties) {
		AnnotatedMethod setter = beanDesc.findMethod(
				"set" + StringUtils.capitalize(writer.getName()),
				new Class<?>[] { writer.getType().getRawClass() });
		if (setter != null && this.conversionService.canConvert(String.class,
				writer.getType().getRawClass())) {
			result.add(writer);
		}
	}
	return result;
}
 
Example 35
Project: autorest-clientruntime-for-java   File: FlatteningSerializer.java   Source Code and License 5 votes vote down vote up
/**
 * Gets a module wrapping this serializer as an adapter for the Jackson
 * ObjectMapper.
 *
 * @param mapper the object mapper for default serializations
 * @return a simple module to be plugged onto Jackson ObjectMapper.
 */
public static SimpleModule getModule(final ObjectMapper mapper) {
    SimpleModule module = new SimpleModule();
    module.setSerializerModifier(new BeanSerializerModifier() {
        @Override
        public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer<?> serializer) {
            if (beanDesc.getBeanClass().getAnnotation(JsonFlatten.class) != null) {
                return new FlatteningSerializer(beanDesc.getBeanClass(), serializer, mapper);
            }
            return serializer;
        }
    });
    return module;
}
 
Example 36
Project: endpoints-java   File: ObjectMapperUtil.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> modifyMapSerializer(SerializationConfig config, MapType valueType,
    BeanDescription beanDesc, JsonSerializer<?> serializer) {
  if (serializer instanceof MapSerializer) {
    // TODO: We should probably be propagating the NON_EMPTY inclusion here, but it's breaking
    // discovery.
    return new DeepEmptyCheckingSerializer<>(serializer);
  }
  return serializer;
}
 
Example 37
Project: emodb   File: LazyJsonModule.java   Source Code and License 5 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
    // Modify the Map serializer to the delegate if it matches Map<String, ?>
    context.addBeanSerializerModifier(new BeanSerializerModifier() {
        @Override
        public JsonSerializer<?> modifyMapSerializer(SerializationConfig config, MapType valueType, BeanDescription beanDesc,
                                                     JsonSerializer<?> serializer) {
            if (valueType.getKeyType().equals(SimpleType.construct(String.class))) {
                return new DelegatingMapSerializer(serializer);
            }
            return serializer;
        }
    });
}
 
Example 38
Project: httpQL   File: BeanPropertyIntrospector.java   Source Code and License 5 votes vote down vote up
private static BeanDescription introspect(Class<?> type) {
  final JavaType javaType;
  SerializationConfig sc = Rosetta.getMapper().getSerializationConfig().withView(RosettaProperty.class);

  javaType = Rosetta.getMapper().getTypeFactory().constructType(type);
  return sc.introspect(javaType);
}
 
Example 39
Project: spring-boot-concourse   File: ConfigurationPropertiesReportEndpoint.java   Source Code and License 5 votes vote down vote up
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config,
		BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
	List<BeanPropertyWriter> result = new ArrayList<BeanPropertyWriter>();
	for (BeanPropertyWriter writer : beanProperties) {
		boolean readable = isReadable(beanDesc, writer);
		if (readable) {
			result.add(writer);
		}
	}
	return result;
}
 
Example 40
Project: spring-boot-concourse   File: DataSourceJsonSerializationTests.java   Source Code and License 5 votes vote down vote up
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config,
		BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
	List<BeanPropertyWriter> result = new ArrayList<BeanPropertyWriter>();
	for (BeanPropertyWriter writer : beanProperties) {
		AnnotatedMethod setter = beanDesc.findMethod(
				"set" + StringUtils.capitalize(writer.getName()),
				new Class<?>[] { writer.getType().getRawClass() });
		if (setter != null && this.conversionService.canConvert(String.class,
				writer.getType().getRawClass())) {
			result.add(writer);
		}
	}
	return result;
}
 
Example 41
Project: evt-bridge   File: ESBeanSerializerModifier.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer<?> serializer) {
	if (serializer instanceof BeanSerializerBase) {
		return new ESBeanSerializer((BeanSerializerBase) serializer);
	}
	
	return serializer;
}
 
Example 42
Project: owsi-core-parent   File: HibernateBeanSerializerModifier.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc,
		JsonSerializer<?> serializer) {
	if (serializer instanceof BeanSerializer) {
		return new BeanSerializerWrapper((BeanSerializer) serializer);
	} else {
		return serializer;
	}
}
 
Example 43
Project: owsi-core-parent   File: HibernateBeanSerializerModifier.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc,
		JsonSerializer<?> serializer) {
	if (serializer instanceof BeanSerializer) {
		return new BeanSerializerWrapper((BeanSerializer) serializer);
	} else {
		return serializer;
	}
}
 
Example 44
Project: contestparser   File: ConfigurationPropertiesReportEndpoint.java   Source Code and License 5 votes vote down vote up
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config,
		BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
	List<BeanPropertyWriter> result = new ArrayList<BeanPropertyWriter>();
	for (BeanPropertyWriter writer : beanProperties) {
		boolean readable = isReadable(beanDesc, writer);
		if (readable) {
			result.add(writer);
		}
	}
	return result;
}
 
Example 45
Project: contestparser   File: DataSourceJsonSerializationTests.java   Source Code and License 5 votes vote down vote up
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config,
		BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
	List<BeanPropertyWriter> result = new ArrayList<BeanPropertyWriter>();
	for (BeanPropertyWriter writer : beanProperties) {
		AnnotatedMethod setter = beanDesc.findMethod(
				"set" + StringUtils.capitalize(writer.getName()),
				new Class<?>[] { writer.getPropertyType() });
		if (setter != null && this.conversionService.canConvert(String.class,
				writer.getPropertyType())) {
			result.add(writer);
		}
	}
	return result;
}
 
Example 46
Project: NyBatisCore   File: SerializerModifier.java   Source Code and License 5 votes vote down vote up
public JsonSerializer<?> modifyCollectionSerializer( SerializationConfig config, CollectionType valueType, BeanDescription beanDesc, JsonSerializer<?> serializer ) {

        Class<?> klass = beanDesc.getBeanClass();

        if( ClassUtil.isExtendedBy(klass, Set.class) ) {
            return new SetSerializer( serializer );
        } else {
            return new ListSerializer( serializer );
        }

    }
 
Example 47
Project: eMonocot   File: CustomHandlerInstantiator.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> serializerInstance(
		SerializationConfig serializationConfig,
		Annotated annotated,
		Class<?> jsonSerializerClass) {
	logger.debug("serializerInstance " +  serializationConfig + " " + annotated + " " + jsonSerializerClass);
	return null;
}
 
Example 48
Project: powop   File: CustomHandlerInstantiator.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> serializerInstance(
		SerializationConfig serializationConfig,
		Annotated annotated,
		Class<?> jsonSerializerClass) {
	logger.debug("serializerInstance " +  serializationConfig + " " + annotated + " " + jsonSerializerClass);
	return null;
}
 
Example 49
Project: vavr-jackson   File: VavrSerializers.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> findReferenceSerializer(SerializationConfig config,
                                                 ReferenceType type, BeanDescription beanDesc,
                                                 TypeSerializer contentTypeSerializer, JsonSerializer<Object> contentValueSerializer) {
    Class<?> raw = type.getRawClass();
    if (Lazy.class.isAssignableFrom(raw)) {
        return new LazySerializer(type);
    }
    if (Option.class.isAssignableFrom(raw)) {
        return new OptionSerializer(type, settings.useOptionInPlainFormat());
    }
    return super.findReferenceSerializer(config, type, beanDesc, contentTypeSerializer, contentValueSerializer);
}
 
Example 50
Project: vavr-jackson   File: VavrSerializers.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> findMapLikeSerializer(SerializationConfig config,
                                               MapLikeType type, BeanDescription beanDesc,
                                               JsonSerializer<Object> keySerializer,
                                               TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) {
    Class<?> raw = type.getRawClass();
    if (Map.class.isAssignableFrom(raw)) {
        return new MapSerializer(type);
    }
    if (Multimap.class.isAssignableFrom(raw)) {
        return new MultimapSerializer(type);
    }
    return super.findMapLikeSerializer(config, type, beanDesc, keySerializer, elementTypeSerializer, elementValueSerializer);
}
 
Example 51
Project: oap   File: LongAdderModule.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> findSerializer( SerializationConfig config, JavaType type, BeanDescription beanDesc ) {
    final Class<?> raw = type.getRawClass();
    if( LongAdder.class.isAssignableFrom( raw ) ) {
        return new LongAdderSerializer();
    }

    return super.findSerializer( config, type, beanDesc );
}
 
Example 52
Project: oap   File: MutableObjectModule.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> findSerializer( SerializationConfig config, JavaType type, BeanDescription beanDesc ) {
    final Class<?> raw = type.getRawClass();
    if( MutableObject.class.isAssignableFrom( raw ) ) {
        return new MutableObjectSerializer( type );
    }

    return super.findSerializer( config, type, beanDesc );
}
 
Example 53
Project: tinytypes   File: TinyTypesSerializers.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc) {
    Class<?> candidateTT = type.getRawClass();
    if (MetaTinyTypes.isTinyType(candidateTT)) {
        return new TinyTypesSerializer(candidateTT);
    }
    return super.findSerializer(config, type, beanDesc);
}
 
Example 54
Project: tinytypes   File: TinyTypesKeySerializers.java   Source Code and License 5 votes vote down vote up
@Override
public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc) {
    Class<?> candidateTT = type.getRawClass();
    if (MetaTinyTypes.isTinyType(candidateTT)) {
        return new TinyTypesKeySerializer<>(candidateTT);
    }
    return super.findSerializer(config, type, beanDesc);
}
 
Example 55
Project: QuizUpWinner   File: EnumSerializer.java   Source Code and License 5 votes vote down vote up
public static EnumSerializer construct(Class<Enum<?>> paramClass, SerializationConfig paramSerializationConfig, BeanDescription paramBeanDescription, JsonFormat.Value paramValue)
{
  AnnotationIntrospector localAnnotationIntrospector = paramSerializationConfig.getAnnotationIntrospector();
  EnumValues localEnumValues;
  if (paramSerializationConfig.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING))
    localEnumValues = EnumValues.constructFromToString(paramClass, localAnnotationIntrospector);
  else
    localEnumValues = EnumValues.constructFromName(paramClass, localAnnotationIntrospector);
  return new EnumSerializer(localEnumValues, _isShapeWrittenUsingIndex(paramClass, paramValue, true));
}
 
Example 56
Project: spring-boot-admin   File: RegistrationBeanSerializerModifier.java   Source Code and License 5 votes vote down vote up
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config,
                                                 BeanDescription beanDesc,
                                                 List<BeanPropertyWriter> beanProperties) {
    if (!Registration.class.isAssignableFrom(beanDesc.getBeanClass())) {
        return beanProperties;
    }

    beanProperties.stream()
                  .filter(beanProperty -> "metadata".equals(beanProperty.getName()))
                  .forEach(beanProperty -> beanProperty.assignSerializer(metadataSerializer));
    return beanProperties;
}
 
Example 57
Project: QuizUpWinner   File: BeanSerializerFactory.java   Source Code and License 5 votes vote down vote up
public JsonSerializer<Object> createSerializer(SerializerProvider paramSerializerProvider, JavaType paramJavaType)
{
  SerializationConfig localSerializationConfig = paramSerializerProvider.getConfig();
  BeanDescription localBeanDescription = localSerializationConfig.introspect(paramJavaType);
  JsonSerializer localJsonSerializer = findSerializerFromAnnotation(paramSerializerProvider, localBeanDescription.getClassInfo());
  if (localJsonSerializer != null)
    return localJsonSerializer;
  JavaType localJavaType1 = modifyTypeByAnnotation(localSerializationConfig, localBeanDescription.getClassInfo(), paramJavaType);
  boolean bool;
  if (localJavaType1 == paramJavaType)
  {
    bool = false;
  }
  else
  {
    bool = true;
    if (!localJavaType1.hasRawClass(paramJavaType.getRawClass()))
      localBeanDescription = localSerializationConfig.introspect(localJavaType1);
  }
  Converter localConverter = localBeanDescription.findSerializationConverter();
  if (localConverter == null)
    return _createSerializer2(paramSerializerProvider, localJavaType1, localBeanDescription, bool);
  JavaType localJavaType2 = localConverter.getOutputType(paramSerializerProvider.getTypeFactory());
  if (!localJavaType2.hasRawClass(localJavaType1.getRawClass()))
    localBeanDescription = localSerializationConfig.introspect(localJavaType2);
  return new StdDelegatingSerializer(localConverter, localJavaType2, _createSerializer2(paramSerializerProvider, localJavaType2, localBeanDescription, true));
}
 
Example 58
Project: ameba   File: FindSerializers.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc) {

    if (jsonContext.isSupportedType(type.getRawClass())) {
        return createSerializer();
    }

    return null;
}
 
Example 59
Project: QuizUpWinner   File: BeanSerializerFactory.java   Source Code and License 5 votes vote down vote up
protected List<BeanPropertyWriter> findBeanProperties(SerializerProvider paramSerializerProvider, BeanDescription paramBeanDescription, BeanSerializerBuilder paramBeanSerializerBuilder)
{
  List localList = paramBeanDescription.findProperties();
  SerializationConfig localSerializationConfig = paramSerializerProvider.getConfig();
  removeIgnorableTypes(localSerializationConfig, paramBeanDescription, localList);
  if (localSerializationConfig.isEnabled(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS))
    removeSetterlessGetters(localSerializationConfig, paramBeanDescription, localList);
  if (localList.isEmpty())
    return null;
  boolean bool = usesStaticTyping(localSerializationConfig, paramBeanDescription, null);
  PropertyBuilder localPropertyBuilder = constructPropertyBuilder(localSerializationConfig, paramBeanDescription);
  ArrayList localArrayList = new ArrayList(localList.size());
  TypeBindings localTypeBindings = paramBeanDescription.bindingsForBeanType();
  Iterator localIterator = localList.iterator();
  while (localIterator.hasNext())
  {
    BeanPropertyDefinition localBeanPropertyDefinition = (BeanPropertyDefinition)localIterator.next();
    AnnotatedMember localAnnotatedMember = localBeanPropertyDefinition.getAccessor();
    if (localBeanPropertyDefinition.isTypeId())
    {
      if (localAnnotatedMember != null)
      {
        if (localSerializationConfig.canOverrideAccessModifiers())
          localAnnotatedMember.fixAccess();
        paramBeanSerializerBuilder.setTypeId(localAnnotatedMember);
      }
    }
    else
    {
      AnnotationIntrospector.ReferenceProperty localReferenceProperty = localBeanPropertyDefinition.findReferenceType();
      if ((localReferenceProperty == null) || (!localReferenceProperty.isBackReference()))
        if ((localAnnotatedMember instanceof AnnotatedMethod))
          localArrayList.add(_constructWriter(paramSerializerProvider, localBeanPropertyDefinition, localTypeBindings, localPropertyBuilder, bool, (AnnotatedMethod)localAnnotatedMember));
        else
          localArrayList.add(_constructWriter(paramSerializerProvider, localBeanPropertyDefinition, localTypeBindings, localPropertyBuilder, bool, (AnnotatedField)localAnnotatedMember));
    }
  }
  return localArrayList;
}
 
Example 60
Project: QuizUpWinner   File: BeanSerializerFactory.java   Source Code and License 5 votes vote down vote up
public TypeSerializer findPropertyContentTypeSerializer(JavaType paramJavaType, SerializationConfig paramSerializationConfig, AnnotatedMember paramAnnotatedMember)
{
  JavaType localJavaType = paramJavaType.getContentType();
  AnnotationIntrospector localAnnotationIntrospector = paramSerializationConfig.getAnnotationIntrospector();
  TypeResolverBuilder localTypeResolverBuilder = localAnnotationIntrospector.findPropertyContentTypeResolver(paramSerializationConfig, paramAnnotatedMember, paramJavaType);
  if (localTypeResolverBuilder == null)
    return createTypeSerializer(paramSerializationConfig, localJavaType);
  return localTypeResolverBuilder.buildTypeSerializer(paramSerializationConfig, localJavaType, paramSerializationConfig.getSubtypeResolver().collectAndResolveSubtypes(paramAnnotatedMember, paramSerializationConfig, localAnnotationIntrospector, localJavaType));
}