public void serialize(Feature value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
        jgen.writeStartObject();
        jgen.writeStringField("type", "Feature");
        if (value != null) {
            Geometry geom = value.getGeometry();
            if (geom == null) {
                jgen.writeNullField("geometry");
            } else {
                // set beanproperty to null since we are not serializing a real property
                JsonSerializer ser = provider.findValueSerializer(geom.getClass(), null);
                if (ser != null && ser instanceof GeometrySerializer) {
                    parent.increaseDepth();
                    jgen.writeFieldName("geometry");
                    ser.serialize(geom, jgen, provider);
                    parent.decreaseDepth();
                }
            }
            Object id = value.getId();
            if (id != null) {
                // Shouldn't happen, but what can you do?
                jgen.writeObjectField("id", id);
            }

            jgen.writeFieldName("properties");
            jgen.writeStartObject();
            for (String propertyName : value.getProperties()) {
                Object propertyContents = value.getProperty(propertyName);
                if (propertyContents != null) {
                    try {
                        // set beanproperty to null since we are not serializing a real property
                        JsonSerializer<Object> ser = provider.findValueSerializer(propertyContents.getClass(), null);
                        if (ser != null) {
                            // Beanserializers have the nasty habit to crash if they don't know how to proceed, leaving
                            // the resulting json in inconsistent state from which it's hard to recover inside a
                            // serialization. We therefore reroute it through the transformer: if it crashes, we just
                            // keep the empty serialization for that specific object instead of invalidating the entire
                            // surrounding json. In addition, they crash with circular references...
                            if (ser instanceof BeanSerializer) {
                                String subPart = parent.recurse(
                                        EntityClassReader.getClassReaderFor(propertyContents.getClass()).asFeature(propertyContents));
                                try {
                                    HashMap subPartMap = parent.getObjectMapper().readValue(subPart, HashMap.class);
                                    jgen.writeFieldName(propertyName);
                                    jgen.writeObject(subPartMap);
                                }
                                catch (IOException ignored) {
                                }
                            } else {
                                jgen.writeFieldName(propertyName);
                                ser.serialize(propertyContents, jgen, provider);
                            }
                        }
                    } catch (JsonMappingException exc) {
                        jgen.writeStartObject();
                        jgen.writeEndObject();
                    } catch (InvalidObjectReaderException e) {
                        // Will not happen!
                    }
                }
            }
            jgen.writeEndObject();
        }
        jgen.writeEndObject();
    }
public void serialize ( Feature value , JsonGenerator jgen , SerializerProvider provider ) throws IOException { jgen . writeStartObject ( ) ; jgen . writeStringField ( "type" , "Feature" ) ; if ( value != null ) { Geometry geom = value . getGeometry ( ) ; if ( geom == null ) { jgen . writeNullField ( "geometry" ) ; } else { JsonSerializer ser = provider . findValueSerializer ( geom . getClass ( ) , null ) ; if ( ser != null && ser instanceof GeometrySerializer ) { parent . increaseDepth ( ) ; jgen . writeFieldName ( "geometry" ) ; ser . serialize ( geom , jgen , provider ) ; parent . decreaseDepth ( ) ; } } Object id = value . getId ( ) ; if ( id != null ) { jgen . writeObjectField ( "id" , id ) ; } jgen . writeFieldName ( "properties" ) ; jgen . writeStartObject ( ) ; for ( String propertyName : value . getProperties ( ) ) { Object propertyContents = value . getProperty ( propertyName ) ; if ( propertyContents != null ) { try { JsonSerializer < Object > ser = provider . findValueSerializer ( propertyContents . getClass ( ) , null ) ; if ( ser != null ) { if ( ser instanceof BeanSerializer ) { String subPart = parent . recurse ( EntityClassReader . getClassReaderFor ( propertyContents . getClass ( ) ) . asFeature ( propertyContents ) ) ; try { HashMap subPartMap = parent . getObjectMapper ( ) . readValue ( subPart , HashMap . class ) ; jgen . writeFieldName ( propertyName ) ; jgen . writeObject ( subPartMap ) ; } catch ( IOException ignored ) { } } else { jgen . writeFieldName ( propertyName ) ; ser . serialize ( propertyContents , jgen , provider ) ; } } } catch ( JsonMappingException exc ) { jgen . writeStartObject ( ) ; jgen . writeEndObject ( ) ; } catch ( InvalidObjectReaderException e ) { } } } jgen . writeEndObject ( ) ; } jgen . writeEndObject ( ) ; }
Method that can be called to ask implementation to serialize values of type this serializer handles.

@param value    Value to serialize; can not be null.
@param jgen     Generator used to output resulting Json content
@param provider Provider that can be used to get serializers for serializing Objects value contains, if any.
@throws java.io.IOException If serialization failed.