com.fasterxml.jackson.databind.ser.impl.UnknownSerializer Java Examples

The following examples show how to use com.fasterxml.jackson.databind.ser.impl.UnknownSerializer. 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: ToStringSerializer.java    From kafka-webview with MIT License 6 votes vote down vote up
@Override
public void serialize(
    final Object value,
    final JsonGenerator gen,
    final SerializerProvider serializers
) throws IOException {
    if (value == null) {
        gen.writeString("");
        return;
    }

    // See if we have a serializer that is NOT the unknown serializer
    final JsonSerializer serializer = serializers.findValueSerializer(value.getClass());
    if (serializer != null && !(serializer instanceof UnknownSerializer)) {
        serializer.serialize(value, gen, serializers);
        return;
    }
    gen.writeString(value.toString());
}
 
Example #2
Source File: StandaloneMockMvcBuilderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test  // SPR-13375
@SuppressWarnings("rawtypes")
public void springHandlerInstantiator() {
	TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
	builder.build();
	SpringHandlerInstantiator instantiator = new SpringHandlerInstantiator(builder.wac.getAutowireCapableBeanFactory());
	JsonSerializer serializer = instantiator.serializerInstance(null, null, UnknownSerializer.class);
	assertNotNull(serializer);
}
 
Example #3
Source File: StandaloneMockMvcBuilderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test  // SPR-13375
@SuppressWarnings("rawtypes")
public void springHandlerInstantiator() {
	TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
	builder.build();
	SpringHandlerInstantiator instantiator = new SpringHandlerInstantiator(builder.wac.getAutowireCapableBeanFactory());
	JsonSerializer serializer = instantiator.serializerInstance(null, null, UnknownSerializer.class);
	assertNotNull(serializer);
}
 
Example #4
Source File: SerializerProvider.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method called to see if given serializer is considered to be
 * something returned by {@link #getUnknownTypeSerializer}, that is, something
 * for which no regular serializer was found or constructed.
 * 
 * @since 2.5
 */
public boolean isUnknownTypeSerializer(JsonSerializer<?> ser) {
    if ((ser == _unknownTypeSerializer) || (ser == null)) {
        return true;
    }
    // 23-Apr-2015, tatu: "empty" serializer is trickier; needs to consider
    //    error handling
    if (isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS)) {
        if (ser.getClass() == UnknownSerializer.class) {
            return true;
        }
    }
    return false;
}
 
Example #5
Source File: StandaloneMockMvcBuilderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void springHandlerInstantiator() {
	TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
	builder.build();
	SpringHandlerInstantiator instantiator = new SpringHandlerInstantiator(builder.wac.getAutowireCapableBeanFactory());
	JsonSerializer serializer = instantiator.serializerInstance(null, null, UnknownSerializer.class);
	assertNotNull(serializer);
}
 
Example #6
Source File: JsonUtils.java    From warp10-platform with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer<?> serializer) {
  if (serializer instanceof UnknownSerializer || serializer instanceof BeanSerializer) {
    return customEncodersSerializer;
  } else {
    return serializer;
  }
}
 
Example #7
Source File: SerializerProvider.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Method called to get the serializer to use if provider
 * cannot determine an actual type-specific serializer
 * to use; typically when none of {@link SerializerFactory}
 * instances are able to construct a serializer.
 *<p>
 * Typically, returned serializer will throw an exception,
 * although alternatively {@link com.fasterxml.jackson.databind.ser.std.ToStringSerializer}
 * could be returned as well.
 *
 * @param unknownType Type for which no serializer is found
 */
public JsonSerializer<Object> getUnknownTypeSerializer(Class<?> unknownType) {
    // 23-Apr-2015, tatu: Only return shared instance if nominal type is Object.class
    if (unknownType == Object.class) {
        return _unknownTypeSerializer;
    }
    // otherwise construct explicit instance with property handled type
    return new UnknownSerializer(unknownType);
}