com.fasterxml.jackson.databind.ser.std.BeanSerializerBase Java Examples

The following examples show how to use com.fasterxml.jackson.databind.ser.std.BeanSerializerBase. 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: CustomFieldModule.java    From albedo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void setupModule(Module.SetupContext context) {
	super.setupModule(context);

	context.addBeanSerializerModifier(new BeanSerializerModifier() {

		@Override
		public JsonSerializer<?> modifySerializer(
			SerializationConfig config,
			BeanDescription beanDesc,
			JsonSerializer<?> serializer) {
			if (serializer instanceof BeanSerializerBase) {
				return new ExtraFieldSerializer(
					(BeanSerializerBase) serializer);
			}
			return serializer;

		}
	});
}
 
Example #2
Source File: RestTemplateTransportClientFactory.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
public static BeanSerializerModifier createJsonSerializerModifier() { // final
	// KeyFormatter
	// keyFormatter,
	// final
	// boolean
	// compactMode)
	// {
	return new BeanSerializerModifier() {
		@Override
		public JsonSerializer<?> modifySerializer(SerializationConfig config,
				BeanDescription beanDesc, JsonSerializer<?> serializer) {
			/*
			 * if (beanDesc.getBeanClass().isAssignableFrom(Applications.class)) {
			 * return new ApplicationsJsonBeanSerializer((BeanSerializerBase)
			 * serializer, keyFormatter); }
			 */
			if (beanDesc.getBeanClass().isAssignableFrom(InstanceInfo.class)) {
				return new InstanceInfoJsonBeanSerializer(
						(BeanSerializerBase) serializer, false);
			}
			return serializer;
		}
	};
}
 
Example #3
Source File: BeanPropertyWriter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method called to handle a direct self-reference through this property.
 * Method can choose to indicate an error by throwing
 * {@link JsonMappingException}; fully handle serialization (and return
 * true); or indicate that it should be serialized normally (return false).
 * <p>
 * Default implementation will throw {@link JsonMappingException} if
 * {@link SerializationFeature#FAIL_ON_SELF_REFERENCES} is enabled; or
 * return <code>false</code> if it is disabled.
 *
 * @return True if method fully handled self-referential value; false if not
 *         (caller is to handle it) or {@link JsonMappingException} if there
 *         is no way handle it
 */
protected boolean _handleSelfReference(Object bean, JsonGenerator gen,
        SerializerProvider prov, JsonSerializer<?> ser)
        throws JsonMappingException {
    if (prov.isEnabled(SerializationFeature.FAIL_ON_SELF_REFERENCES)
            && !ser.usesObjectId()) {
        // 05-Feb-2013, tatu: Usually a problem, but NOT if we are handling
        // object id; this may be the case for BeanSerializers at least.
        // 13-Feb-2014, tatu: another possible ok case: custom serializer
        // (something
        // OTHER than {@link BeanSerializerBase}
        if (ser instanceof BeanSerializerBase) {
            prov.reportBadDefinition(getType(), "Direct self-reference leading to cycle");
        }
    }
    return false;
}
 
Example #4
Source File: BeanSerializer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Implementation has to check whether as-array serialization
 * is possible reliably; if (and only if) so, will construct
 * a {@link BeanAsArraySerializer}, otherwise will return this
 * serializer as is.
 */
@Override
protected BeanSerializerBase asArraySerializer()
{
    /* Cannot:
     * 
     * - have Object Id (may be allowed in future)
     * - have "any getter"
     * - have per-property filters
     */
    if ((_objectIdWriter == null)
            && (_anyGetterWriter == null)
            && (_propertyFilterId == null)
            ) {
        return new BeanAsArraySerializer(this);
    }
    // already is one, so:
    return this;
}
 
Example #5
Source File: JacksonDictJsonModifier.java    From cola-cloud with MIT License 5 votes vote down vote up
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config,
                                          BeanDescription beanDesc, JsonSerializer<?> serializer) {
    JsonDict jsonDict = beanDesc.getBeanClass().getAnnotation(JsonDict.class);
    if(jsonDict != null){
        serializer = new JsonDictSerializer((BeanSerializerBase) serializer, dictClient,jsonDict);
    }
    return serializer;
}
 
Example #6
Source File: JacksonTest.java    From albedo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testAddExtraField() throws Exception {
	ObjectMapper mapper = new ObjectMapper();

	mapper.registerModule(new SimpleModule() {

		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 ExtraFieldSerializer(
							(BeanSerializerBase) serializer);
					}
					return serializer;

				}
			});
		}
	});

	mapper.writeValue(System.out, Lists.newArrayList(new MyClass1(), new MyClass2()));
	//prints {"classField":"classFieldValue","extraField":"extraFieldValue"}
}
 
Example #7
Source File: WebClientTransportClientFactory.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Deprecated // reduce visibility in future release
public static BeanSerializerModifier createJsonSerializerModifier() {
	return new BeanSerializerModifier() {
		@Override
		public JsonSerializer<?> modifySerializer(SerializationConfig config,
				BeanDescription beanDesc, JsonSerializer<?> serializer) {
			if (beanDesc.getBeanClass().isAssignableFrom(InstanceInfo.class)) {
				return new InstanceInfoJsonBeanSerializer(
						(BeanSerializerBase) serializer, false);
			}
			return serializer;
		}
	};
}
 
Example #8
Source File: FlatRBeanSerializerModifier.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public JsonSerializer<?> modifySerializer(
    SerializationConfig config,
    BeanDescription beanDesc,
    JsonSerializer<?> serializer
) {
  // Only use the serializer for any subclasses of RType
  if (RType.class.isAssignableFrom(beanDesc.getBeanClass()) && serializer instanceof BeanSerializerBase) {
    return new RBeanContextData((BeanSerializerBase) serializer);
  }
  return serializer;
}
 
Example #9
Source File: AbstractBeanSerializer.java    From caravan with Apache License 2.0 5 votes vote down vote up
@Override
protected BeanSerializerBase asArraySerializer() {
  if ((_objectIdWriter == null)
      && (_anyGetterWriter == null)
      && (_propertyFilterId == null)
      ) {
    return new BeanAsArraySerializer(this);
  }
  // already is one, so:
  return this;
}
 
Example #10
Source File: JsonldResourceSerializerModifier.java    From jackson-jsonld with MIT License 5 votes vote down vote up
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer<?> serializer) {
    if(AnnotationsUtils.isAnnotationPresent(beanDesc.getBeanClass(), JsonldResource.class) && serializer instanceof BeanSerializerBase){
        return new JsonldResourceSerializer((BeanSerializerBase) serializer);
    }
    return serializer;
}
 
Example #11
Source File: AbstractBeanSerializer.java    From caravan with Apache License 2.0 4 votes vote down vote up
@Override
public BeanSerializerBase withFilterId(Object filterId) {
  return this;
}
 
Example #12
Source File: BeanSerializer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected BeanSerializer(BeanSerializerBase src, Set<String> toIgnore) {
    super(src, toIgnore);
}
 
Example #13
Source File: AbstractBeanSerializer.java    From caravan with Apache License 2.0 4 votes vote down vote up
@Override
public BeanSerializerBase withObjectIdWriter(ObjectIdWriter objectIdWriter) {
  return this;
}
 
Example #14
Source File: BeanSerializer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected BeanSerializerBase withIgnorals(Set<String> toIgnore) {
    return new BeanSerializer(this, toIgnore);
}
 
Example #15
Source File: BeanSerializer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BeanSerializerBase withFilterId(Object filterId) {
    return new BeanSerializer(this, _objectIdWriter, filterId);
}
 
Example #16
Source File: BeanSerializer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BeanSerializerBase withObjectIdWriter(ObjectIdWriter objectIdWriter) {
    return new BeanSerializer(this, objectIdWriter, _propertyFilterId);
}
 
Example #17
Source File: JsonDictSerializer.java    From cola-cloud with MIT License 4 votes vote down vote up
public JsonDictSerializer(BeanSerializerBase src, DictClient dictClient, JsonDict jsonDict) {
    super(src);
    this.jsonDict = jsonDict;
    this.dictClient = dictClient;
}
 
Example #18
Source File: AbstractBeanSerializer.java    From caravan with Apache License 2.0 4 votes vote down vote up
@Override
protected BeanSerializerBase withIgnorals(Set<String> toIgnore) {
  return this;
}
 
Example #19
Source File: JsonldResourceSerializer.java    From jackson-jsonld with MIT License 4 votes vote down vote up
public JsonldResourceSerializer(BeanSerializerBase src) {
    super(src);
}
 
Example #20
Source File: FlatRBeanSerializerModifier.java    From datacollector with Apache License 2.0 4 votes vote down vote up
RBeanContextData(BeanSerializerBase source) {
  super(source);
}
 
Example #21
Source File: FlatRBeanSerializerModifier.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public BeanSerializerBase withObjectIdWriter(ObjectIdWriter objectIdWriter) {
  return new RBeanContextData(this, objectIdWriter);
}
 
Example #22
Source File: FlatRBeanSerializerModifier.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Override
protected BeanSerializerBase withIgnorals(Set<String> toIgnore) {
  return null;
}
 
Example #23
Source File: FlatRBeanSerializerModifier.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Override
protected BeanSerializerBase asArraySerializer() {
  return null;
}
 
Example #24
Source File: FlatRBeanSerializerModifier.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Override
public BeanSerializerBase withFilterId(Object filterId) {
  return null;
}
 
Example #25
Source File: BeanAsArraySerializer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BeanSerializerBase withFilterId(Object filterId) {
    return new BeanAsArraySerializer(this, _objectIdWriter, filterId);
}
 
Example #26
Source File: ExtraFieldSerializer.java    From albedo with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ExtraFieldSerializer(BeanSerializerBase source) {
	super(source);
}
 
Example #27
Source File: ExtraFieldSerializer.java    From albedo with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public BeanSerializerBase withObjectIdWriter(
	ObjectIdWriter objectIdWriter) {
	return new ExtraFieldSerializer(this, objectIdWriter);
}
 
Example #28
Source File: ExtraFieldSerializer.java    From albedo with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected BeanSerializerBase withIgnorals(Set<String> toIgnore) {
	return new ExtraFieldSerializer(this, toIgnore);
}
 
Example #29
Source File: ExtraFieldSerializer.java    From albedo with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected BeanSerializerBase asArraySerializer() {
	return (this._objectIdWriter == null && this._anyGetterWriter == null && this._propertyFilterId == null ? new BeanAsArraySerializer(this) : this);
}
 
Example #30
Source File: ExtraFieldSerializer.java    From albedo with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public BeanSerializerBase withFilterId(Object filterId) {
	return new ExtraFieldSerializer(this, this._objectIdWriter, filterId);
}