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)); } 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; }  static DBObject convert(SimpleFeatureType ft); static SimpleFeatureType convert(DBObject ftDBO); static SimpleFeatureType convert(DBObject ftDBO, Name name);  }
@Test public void testRoundTripConversion() throws FileNotFoundException, IOException, FactoryException { SimpleFeatureType original = buildDummyFeatureType("dummy"); DBObject dbo = FeatureTypeDBObject.convert(original); StringBuilder jsonBuffer = new StringBuilder(); JSON.serialize(dbo, jsonBuffer); String json = jsonBuffer.toString(); System.out.println(MongoTestUtil.prettyPrint(json)); Object o = JSON.parse(json); assertThat(o, is(instanceOf(DBObject.class))); dbo = (DBObject)o; SimpleFeatureType result = FeatureTypeDBObject.convert(dbo); compareFeatureTypes(original, result, false); }