Java Code Examples for com.fasterxml.jackson.databind.SerializerProvider#findTypedValueSerializer()

The following examples show how to use com.fasterxml.jackson.databind.SerializerProvider#findTypedValueSerializer() . 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: HListSerializer.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
void write(Object val, int containedTypeIndex, JsonGenerator gen, SerializerProvider provider) throws IOException {
    if (val != null) {
        if (type.containedTypeCount() > containedTypeIndex) {
            JsonSerializer<Object> ser;
            JavaType containedType = type.containedType(containedTypeIndex);
            if (containedType != null && containedType.hasGenericTypes()) {
                JavaType st = provider.constructSpecializedType(containedType, val.getClass());
                ser = provider.findTypedValueSerializer(st, true, null);
            } else {
                ser = provider.findTypedValueSerializer(val.getClass(), true, null);
            }
            ser.serialize(val, gen, provider);
        } else {
            gen.writeObject(val);
        }
    } else {
        gen.writeNull();
    }
}
 
Example 2
Source File: ValueSerializer.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(T value, JsonGenerator gen, SerializerProvider provider) throws IOException {
    Object obj = toJavaObj(value);
    if (obj == null) {
        provider.getDefaultNullValueSerializer().serialize(null, gen, provider);
    } else {
        JsonSerializer<Object> ser;
        try {
            JavaType emulated = emulatedJavaType(provider.getTypeFactory());
            if (emulated.getRawClass() != Object.class) {
                ser = provider.findTypedValueSerializer(emulated, true, beanProperty);
            } else {
                ser = provider.findTypedValueSerializer(obj.getClass(), true, beanProperty);
            }
        } catch (Exception ignore) {
            ser = provider.findTypedValueSerializer(obj.getClass(), true, beanProperty);
        }
        ser.serialize(obj, gen, provider);
    }
}
 
Example 3
Source File: JoynrListSerializer.java    From joynr with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(List<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException,
                                                                                      JsonGenerationException {

    jgen.writeStartArray();
    for (Object elem : value) {
        if (elem == null) {
            provider.defaultSerializeNull(jgen);
        } else {
            Class<?> clazz = elem.getClass();
            JsonSerializer<Object> serializer = serializers.get(clazz);
            if (serializer == null) {
                serializer = provider.findTypedValueSerializer(clazz, false, null);
            }
            serializer.serialize(elem, jgen, provider);
        }
    }
    jgen.writeEndArray();

}
 
Example 4
Source File: JoynrArraySerializer.java    From joynr with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(Object[] value, JsonGenerator gen, SerializerProvider provider) throws IOException {
    gen.writeStartArray();
    for (Object elem : value) {
        if (elem == null) {
            provider.defaultSerializeNull(gen);
        } else {
            Class<?> clazz = elem.getClass();
            JsonSerializer<Object> serializer = serializers.get(clazz);
            if (serializer == null) {
                serializer = provider.findTypedValueSerializer(clazz, false, null);
            }
            serializer.serialize(elem, gen, provider);
        }
    }
    gen.writeEndArray();

}
 
Example 5
Source File: PropertySerializerMap.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 2.5
 */
public final SerializerAndMapResult findAndAddRootValueSerializer(JavaType type,
        SerializerProvider provider)
    throws JsonMappingException
{
    JsonSerializer<Object> serializer = provider.findTypedValueSerializer(type, false, null);
    return new SerializerAndMapResult(serializer, newWith(type.getRawClass(), serializer));
}
 
Example 6
Source File: Tuple2Serializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Tuple2<?,?> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {


  Object[] array = new Object[]{value._1(),value._2()};
  gen.writeStartArray();
  for(Object o : array) {
    JsonSerializer<Object> ser = serializers.findTypedValueSerializer(o.getClass(),true,null);
    ser.serialize(o, gen, serializers);
  }
  gen.writeEndArray();

}
 
Example 7
Source File: Tuple3Serializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Tuple3<?,?,?> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {

  Object[] array = new Object[]{value._1(),value._2(),value._3()};
  gen.writeStartArray();
  for(Object o : array) {
    JsonSerializer<Object> ser = serializers.findTypedValueSerializer(o.getClass(),true,null);
    ser.serialize(o, gen, serializers);
  }
  gen.writeEndArray();

}
 
Example 8
Source File: Tuple7Serializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Tuple7<?,?,?,?,?,?,?> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
  Object[] array = new Object[]{value._1(),value._2(),value._3(),value._4(),value._5(),value._6(),value._7()};
  gen.writeStartArray();
  for(Object o : array) {
    JsonSerializer<Object> ser = serializers.findTypedValueSerializer(o.getClass(),true,null);
    ser.serialize(o, gen, serializers);
  }
  gen.writeEndArray();
}
 
Example 9
Source File: Tuple8Serializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Tuple8<?,?,?,?,?,?,?,?> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {

  Object[] array = new Object[]{value._1(),value._2(),value._3(),value._4(),value._5(),value._6(),value._7(),value._8()};
  gen.writeStartArray();
  for(Object o : array) {
    JsonSerializer<Object> ser = serializers.findTypedValueSerializer(o.getClass(),true,null);
    ser.serialize(o, gen, serializers);
  }
  gen.writeEndArray();
}
 
Example 10
Source File: Tuple6Serializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Tuple6<?,?,?,?,?,?> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {

  Object[] array = new Object[]{value._1(),value._2(),value._3(),value._4(),value._5(),value._6()};
  gen.writeStartArray();
  for(Object o : array) {
    JsonSerializer<Object> ser = serializers.findTypedValueSerializer(o.getClass(),true,null);
    ser.serialize(o, gen, serializers);
  }
  gen.writeEndArray();
}
 
Example 11
Source File: Tuple5Serializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Tuple5<?,?,?,?,?> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {

  Object[] array = new Object[]{value._1(),value._2(),value._3(),value._4(),value._5()};
  gen.writeStartArray();
  for(Object o : array) {
    JsonSerializer<Object> ser = serializers.findTypedValueSerializer(o.getClass(),true,null);
    ser.serialize(o, gen, serializers);
  }
  gen.writeEndArray();
}
 
Example 12
Source File: Tuple4Serializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Tuple4<?,?,?,?> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {

  Object[] array = new Object[]{value._1(),value._2(),value._3(),value._4()};
  gen.writeStartArray();
  for(Object o : array) {
    JsonSerializer<Object> ser = serializers.findTypedValueSerializer(o.getClass(),true,null);
    ser.serialize(o, gen, serializers);
  }
  gen.writeEndArray();

}
 
Example 13
Source File: IterableXSerializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Iterable<?> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
  if(value==null) {
    gen.writeNull();
    return;
  }
  gen.writeStartArray();
  for(Object o : value) {
    JsonSerializer<Object> ser = serializers.findTypedValueSerializer(o.getClass(),true,null);
    ser.serialize(o, gen, serializers);
  }
  gen.writeEndArray();
}
 
Example 14
Source File: Tuple1Serializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Tuple1<?> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {


    Object[] array = new Object[]{value._1()};
    gen.writeStartArray();
    for(Object o : array) {
      JsonSerializer<Object> ser = serializers.findTypedValueSerializer(o.getClass(),true,null);
      ser.serialize(o, gen, serializers);
    }
    gen.writeEndArray();


}
 
Example 15
Source File: ContextualStoredAsJsonSerializer.java    From Rosetta with Apache License 2.0 5 votes vote down vote up
private boolean trySerializeToGenerator(T value, ObjectMapper mapper, SerializerProvider provider, JsonGenerator gen) throws IOException {
  JsonSerializer<Object> serializer = provider.findTypedValueSerializer(
      mapper.getTypeFactory().constructSpecializedType(property.getType(), value.getClass()),
      false,
      null);

  if (serializer == null) {
    return false;
  }

  mapper.getSerializationConfig().initialize(gen);
  serializer.serialize(value, gen, provider);
  return true;
}
 
Example 16
Source File: PropertySerializerMap.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Method called if initial lookup fails, when looking for a root value
 * serializer: one that is not directly attached to a property, but needs to
 * have {@link com.fasterxml.jackson.databind.jsontype.TypeSerializer} wrapped
 * around it. Will both find the serializer
 * and construct new map instance if warranted, and return both.
 * 
 * @since 2.5
 * 
 * @throws JsonMappingException 
 */
public final SerializerAndMapResult findAndAddRootValueSerializer(Class<?> type,
        SerializerProvider provider)
    throws JsonMappingException
{
    JsonSerializer<Object> serializer = provider.findTypedValueSerializer(type, false, null);
    return new SerializerAndMapResult(serializer, newWith(type, serializer));
}