Ejemplo n.º 1
0
 @Override
 public void serializeAsField(Object bean, JsonGenerator jgen, SerializerProvider prov)
     throws Exception {
   // We know the type (although interface can't expose it)
   String value = ((Bean) bean).name;
   // Convert nulls to "", otherwise upper case
   value = (value == null) ? "" : value.toUpperCase();
   jgen.writeStringField("name", value);
 }
Ejemplo n.º 2
0
 @Override
 @SuppressWarnings("deprecation")
 public void serialize(JsonGenerator jgen, SerializerProvider provider)
     throws IOException, JsonProcessingException {
   // First, wrapping:
   if (_prefix != null) jgen.writeRaw(_prefix);
   if (_value == null) {
     provider.defaultSerializeNull(jgen);
   } else if (_serializationType != null) {
     provider
         .findTypedValueSerializer(_serializationType, true, null)
         .serialize(_value, jgen, provider);
   } else {
     Class<?> cls = _value.getClass();
     provider.findTypedValueSerializer(cls, true, null).serialize(_value, jgen, provider);
   }
   if (_suffix != null) jgen.writeRaw(_suffix);
 }