Index: DefaultFeatureReference.java
===================================================================
--- DefaultFeatureReference.java	(revision 43827)
+++ DefaultFeatureReference.java	(revision 43828)
@@ -25,6 +25,7 @@
 
 import java.lang.ref.WeakReference;
 import java.util.Arrays;
+import java.util.Base64;
 import java.util.List;
 import org.apache.commons.lang3.ArrayUtils;
 
@@ -40,6 +41,8 @@
 import org.gvsig.tools.persistence.Persistent;
 import org.gvsig.tools.persistence.PersistentState;
 import org.gvsig.tools.persistence.exception.PersistenceException;
+import org.json.JSONArray;
+import org.json.JSONObject;
 
 public class DefaultFeatureReference implements
 		FeatureReferenceProviderServices, Persistent {
@@ -52,6 +55,15 @@
 	private boolean isNewFeature;
 	private String featureTypeId;
 	 
+        
+        private final int OID_INDEX = 0;
+        private final int MYHASHCODE_INDEX = 1;
+        private final int ISNEWFEATURE_INDEX = 2;
+        private final int FEATURETYPEID_INDEX = 3;
+        private final int PKNAMES_SIZE_INDEX = 4;
+        private final int PKNAMES_INDEX = 5;
+        private final int PK_INDEX = 6;
+        
 	/**
      * Constructor used by the persistence manager. Don't use directly.
      * After to invoke this method, the persistence manager calls 
@@ -108,7 +120,61 @@
 		this.storeRef = new WeakReference(store);
 	}
 
-	private DefaultFeatureStore getStore() {
+	public DefaultFeatureReference(FeatureStore store, String code) {
+            this.storeRef = new WeakReference(store);
+            
+            String json = new String(Base64.getDecoder().decode(code.getBytes()));
+            
+            JSONArray x = new JSONArray(json);
+            this.oid = x.get(OID_INDEX);
+            if( x.get(MYHASHCODE_INDEX)==JSONObject.NULL ) {
+                this.myHashCode = null;
+            } else {
+                this.myHashCode = x.getInt(MYHASHCODE_INDEX);
+            }
+            this.isNewFeature = x.getBoolean(ISNEWFEATURE_INDEX);
+            this.featureTypeId = x.getString(FEATURETYPEID_INDEX);
+            int pkNames_size = x.getInt(PKNAMES_SIZE_INDEX);
+            if( pkNames_size<0 ) {
+                this.pk = null;
+                this.pkNames = null;
+            } else {
+                this.pk = new Object[pkNames_size];
+                this.pkNames = new String[pkNames_size];
+                JSONArray xx = x.getJSONArray(PKNAMES_INDEX);
+                for( int i=0; i<xx.length(); i++ ) {
+                    this.pkNames[i] = xx.getString(i);
+                }
+                xx = x.getJSONArray(PKNAMES_INDEX);
+                for( int i=0; i<xx.length(); i++ ) {
+                    this.pk[i] = xx.get(i);
+                }
+            }
+            
+//            JSONObject x = new JSONObject(json);
+//            this.oid = x.get("oid");
+//            this.myHashCode = x.getInt("myHashCode");
+//            this.isNewFeature = x.getBoolean("isNewFeature");
+//            this.featureTypeId = x.getString("featureTypeId");
+//            int pkNames_size = x.getInt("pkNames_size");
+//            if( pkNames_size<0 ) {
+//                this.pk = null;
+//                this.pkNames = null;
+//            } else {
+//                this.pk = new Object[pkNames_size];
+//                this.pkNames = new String[pkNames_size];
+//                JSONArray xx = x.getJSONArray("pkNames");
+//                for( int i=0; i<xx.length(); i++ ) {
+//                    this.pkNames[i] = xx.getString(i);
+//                }
+//                xx = x.getJSONArray("pk");
+//                for( int i=0; i<xx.length(); i++ ) {
+//                    this.pk[i] = xx.get(i);
+//                }
+//            }
+        }
+        
+        private DefaultFeatureStore getStore() {
 		return (DefaultFeatureStore) this.storeRef.get();
 	}
 
@@ -263,6 +329,44 @@
 		}
 
 	}
+        
+        @Override
+        public String getCode() {
+//            JSONObject x = new JSONObject();
+////            x.put("store", (Persistent) storeRef.get());
+//            x.put("oid", oid);
+//            x.put("myHashCode", myHashCode);
+//            x.put("isNewFeature", isNewFeature);
+//            x.put("featureTypeId", featureTypeId);
+//            if( this.pk == null ) {
+//                x.put("pkNames_size", -1);
+//                x.put("pkNames", JSONObject.NULL);
+//                x.put("pk", JSONObject.NULL);
+//            } else {
+//                x.put("pkNames_size", pkNames.length);
+//                x.put("pkNames", new JSONArray(this.pkNames));
+//                x.put("pk", new JSONArray(this.pk));
+//            }
+//
+            Object[] data = new Object[7];
+            data[OID_INDEX] = this.oid;
+            data[MYHASHCODE_INDEX] = this.myHashCode;
+            data[ISNEWFEATURE_INDEX] = this.isNewFeature;
+            data[FEATURETYPEID_INDEX] = this.featureTypeId;
+            if( this.pk == null ) {
+                data[PKNAMES_SIZE_INDEX] = -1;
+                data[PKNAMES_INDEX] = JSONObject.NULL;
+                data[PK_INDEX] = JSONObject.NULL;
+            } else {
+                data[PKNAMES_SIZE_INDEX] = pkNames.length;
+                data[PKNAMES_INDEX] = new JSONArray(this.pkNames);
+                data[PK_INDEX] = new JSONArray(this.pk);            
+            }            
+            String s = new JSONArray(data).toString();
+            String r = Base64.getEncoder().encodeToString(s.getBytes());
+            
+            return r;
+        }
 
 	public static void registerPersistent() {
 		DynStruct definition = ToolsLocator.getPersistenceManager().addDefinition(
