class FeatureTypeDBObject {

    public static DBObject convert(SimpleFeatureType ft) {

        DBObject ftDBO = new BasicDBObject(KEY_typeName, ft.getTypeName());
        Map<String, String> ftUserData = typeCheck(ft.getUserData());
        if (!ftUserData.isEmpty()) {
            ftDBO.put(KEY_userData, new BasicDBObject(ftUserData));
        }

        // for geometry descriptor, just store name to reference against attribute
        GeometryDescriptor gd = ft.getGeometryDescriptor();
        String gdLocalName = gd.getLocalName();
        DBObject gdDBO = new BasicDBObject(KEY_localName, gdLocalName);
        CoordinateReferenceSystem crs = gd.getCoordinateReferenceSystem();
        if (crs == null) {
            crs = DefaultGeographicCRS.WGS84;
        }
        DBObject crsDBO = encodeCRSToGeoJSON(crs);
        if (crsDBO != null) {
            gdDBO.put(KEY_crs, crsDBO);
        }
        ftDBO.put(KEY_geometryDescriptor, gdDBO);

        BasicDBList adDBL = new BasicDBList();
        for (AttributeDescriptor ad : ft.getAttributeDescriptors()) {
            String adLocalName = ad.getLocalName();
            DBObject adDBO = new BasicDBObject(KEY_localName, adLocalName);
            if (!adLocalName.equals(gdLocalName)) {
                Object dv = ad.getDefaultValue();
                if (dv != null) {
                    adDBO.put(KEY_defaultValue, dv);
                }
                adDBO.put(KEY_minOccurs, ad.getMinOccurs());
                adDBO.put(KEY_maxOccurs, ad.getMaxOccurs());
            }
            Class<?> binding = ad instanceof GeometryDescriptor ? Geometry.class : ad.getType()
                    .getBinding();
            adDBO.put(KEY_type, new BasicDBObject(KEY_binding, binding.getName()));
            Map<String, String> adUserData = typeCheck(ad.getUserData());
            if (!adUserData.isEmpty()) {
                adDBO.put(KEY_userData, new BasicDBObject(adUserData));
            }
            adDBL.add(adDBO);
        }
        ftDBO.put(KEY_attributeDescriptors, adDBL);
        return ftDBO;
    }

}