| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.apache.shindig.social.core.util; |
| 19 | |
|
| 20 | |
import com.google.common.collect.Maps; |
| 21 | |
|
| 22 | |
import org.apache.shindig.social.opensocial.model.Address; |
| 23 | |
import org.apache.shindig.social.opensocial.model.Enum; |
| 24 | |
import org.apache.shindig.social.opensocial.model.ListField; |
| 25 | |
import org.apache.shindig.social.opensocial.model.MediaItem; |
| 26 | |
import org.apache.shindig.social.opensocial.model.Organization; |
| 27 | |
import org.apache.shindig.social.opensocial.model.Url; |
| 28 | |
|
| 29 | |
import com.google.inject.Inject; |
| 30 | |
import com.google.inject.Injector; |
| 31 | |
import net.sf.ezmorph.MorpherRegistry; |
| 32 | |
import net.sf.json.JsonConfig; |
| 33 | |
import net.sf.json.util.EnumMorpher; |
| 34 | |
import net.sf.json.util.JSONUtils; |
| 35 | |
|
| 36 | |
import java.util.HashMap; |
| 37 | |
import java.util.Map; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
public class BeanJsonLibConfig extends JsonConfig { |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
static { |
| 49 | 1 | MorpherRegistry morpherRegistry = JSONUtils.getMorpherRegistry(); |
| 50 | 1 | morpherRegistry.registerMorpher(new EnumMorpher(Address.Field.class)); |
| 51 | 1 | morpherRegistry.registerMorpher(new EnumMorpher(ListField.Field.class)); |
| 52 | 1 | morpherRegistry.registerMorpher(new EnumMorpher(ListField.Field.class)); |
| 53 | 1 | morpherRegistry.registerMorpher(new EnumMorpher(MediaItem.Field.class)); |
| 54 | 1 | morpherRegistry.registerMorpher(new EnumMorpher(MediaItem.Type.class)); |
| 55 | 1 | morpherRegistry.registerMorpher(new EnumMorpher(Enum.Drinker.class)); |
| 56 | 1 | morpherRegistry.registerMorpher(new EnumMorpher(Enum.Field.class)); |
| 57 | 1 | morpherRegistry.registerMorpher(new EnumMorpher(Enum.NetworkPresence.class)); |
| 58 | 1 | morpherRegistry.registerMorpher(new EnumMorpher(Enum.Smoker.class)); |
| 59 | 1 | morpherRegistry.registerMorpher(new JsonObjectToMapMorpher()); |
| 60 | 1 | } |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
@Inject |
| 67 | 10 | public BeanJsonLibConfig(Injector injector) { |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | 10 | setNewBeanInstanceStrategy(new InjectorBeanInstanceStrategy(injector)); |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | 10 | registerDefaultValueProcessor(String.class, new NullDefaultValueProcessor()); |
| 78 | |
|
| 79 | 10 | setJsonPropertyFilter(new NullPropertyFilter()); |
| 80 | 10 | setJavaPropertyFilter(new NullPropertyFilter()); |
| 81 | |
|
| 82 | |
|
| 83 | 10 | Map<String, Class<?>> classMap = Maps.newHashMap(); |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | 10 | classMap.put("mediaItems", MediaItem.class); |
| 97 | |
|
| 98 | 10 | classMap.put("templateParams", Map.class); |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | 10 | classMap.put("addresses", Address.class); |
| 111 | 10 | classMap.put("phoneNumbers", ListField.class); |
| 112 | 10 | classMap.put("emails", ListField.class); |
| 113 | 10 | classMap.put("mediaItems", MediaItem.class); |
| 114 | 10 | classMap.put("jobs", Organization.class); |
| 115 | 10 | classMap.put("schools", Organization.class); |
| 116 | 10 | classMap.put("urls", Url.class); |
| 117 | 10 | setClassMap(classMap); |
| 118 | |
|
| 119 | 10 | } |
| 120 | |
|
| 121 | |
} |