Subversion Repositories SmartDukaan

Rev

Rev 8749 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8749 Rev 8865
Line 1... Line 1...
1
package in.shop2020.storage.mongo.adapters;
1
package in.shop2020.storage.mongo.adapters;
2
 
2
 
3
import in.shop2020.metamodel.core.FreeformContent;
3
import in.shop2020.metamodel.core.FreeformContent;
-
 
4
import in.shop2020.metamodel.core.Media;
4
 
5
 
5
import java.lang.reflect.Type;
6
import java.lang.reflect.Type;
-
 
7
import java.util.HashSet;
-
 
8
import java.util.Iterator;
-
 
9
import java.util.LinkedHashMap;
-
 
10
import java.util.Map;
-
 
11
 
-
 
12
import org.apache.commons.collections.MapUtils;
6
 
13
 
7
import com.google.gson.Gson;
14
import com.google.gson.Gson;
8
import com.google.gson.JsonElement;
15
import com.google.gson.JsonElement;
9
import com.google.gson.JsonSerializationContext;
16
import com.google.gson.JsonSerializationContext;
10
import com.google.gson.JsonSerializer;
17
import com.google.gson.JsonSerializer;
11
 
18
 
12
public class FFCAdapter implements JsonSerializer<FreeformContent> {
19
public class FFCAdapter implements JsonSerializer<FreeformContent> {
-
 
20
	
-
 
21
    private static long counter = 0;
-
 
22
    
13
    @Override
23
    @Override
14
    public JsonElement serialize(FreeformContent src, Type typeOfSrc, JsonSerializationContext context) {
24
    public JsonElement serialize(FreeformContent src, Type typeOfSrc, JsonSerializationContext context) {
-
 
25
    	Map<String, Media> medias  = src.getMedias();
-
 
26
    	if (MapUtils.isEmpty(medias)){
-
 
27
    		Iterator<String> iter = new HashSet<String>(medias.keySet()).iterator();
-
 
28
    		while (iter.hasNext()) {
-
 
29
    			String key= iter.next();
-
 
30
    			medias.put(Long.toString(++counter),medias.remove(key));
-
 
31
    		}
15
    	src.getMedias();
32
    		System.out.println(src.getMedias());
-
 
33
    	}
16
        return new Gson().toJsonTree(src);
34
    	return new Gson().toJsonTree(src);
17
    }
35
    }
18
 
36
 
19
}
37
}