@Test public void testToSoyCompatibleObjectsWhenObjectIsString() throws Exception { String testInput = "test"; Object testObject = objectToSoyDataConverter .toSoyCompatibleObjects(testInput); assertEquals("test", testObject.toString()); }
protected Object toSoyCompatibleObjects(Object obj) throws Exception { if (obj == null) { return obj; } if (Primitives.isWrapperType(obj.getClass()) || obj instanceof String) { return obj; } if(obj.getClass().isEnum()) { return ((Enum)obj).name(); } if (obj instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) obj; Map<String, Object> newMap = new HashMap<String, Object>(map.size()); for (String key : map.keySet()) { newMap.put(key, toSoyCompatibleObjects(map.get(key))); } return newMap; } if (obj instanceof Iterable<?>) { List<Object> list = Lists.newArrayList(); for (Object subValue : ((Iterable<?>) obj)) { list.add(toSoyCompatibleObjects(subValue)); } return list; } if (obj instanceof Callable) { final Callable<?> callable = (Callable<?>) obj; return toSoyCompatibleObjects(callable.call()); } if (obj.getClass().isArray()) { return obj; } @SuppressWarnings("unchecked") Map<String, Object> pojoMap = (Map<String, Object>) pojoToMap(obj); Map<String, Object> newMap = new HashMap<String, Object>(pojoMap.size()); for (String key : pojoMap.keySet()) { newMap.put(key, toSoyCompatibleObjects(pojoMap.get(key))); } return newMap; }
DefaultToSoyDataConverter implements ToSoyDataConverter { protected Object toSoyCompatibleObjects(Object obj) throws Exception { if (obj == null) { return obj; } if (Primitives.isWrapperType(obj.getClass()) || obj instanceof String) { return obj; } if(obj.getClass().isEnum()) { return ((Enum)obj).name(); } if (obj instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) obj; Map<String, Object> newMap = new HashMap<String, Object>(map.size()); for (String key : map.keySet()) { newMap.put(key, toSoyCompatibleObjects(map.get(key))); } return newMap; } if (obj instanceof Iterable<?>) { List<Object> list = Lists.newArrayList(); for (Object subValue : ((Iterable<?>) obj)) { list.add(toSoyCompatibleObjects(subValue)); } return list; } if (obj instanceof Callable) { final Callable<?> callable = (Callable<?>) obj; return toSoyCompatibleObjects(callable.call()); } if (obj.getClass().isArray()) { return obj; } @SuppressWarnings("unchecked") Map<String, Object> pojoMap = (Map<String, Object>) pojoToMap(obj); Map<String, Object> newMap = new HashMap<String, Object>(pojoMap.size()); for (String key : pojoMap.keySet()) { newMap.put(key, toSoyCompatibleObjects(pojoMap.get(key))); } return newMap; } }
DefaultToSoyDataConverter implements ToSoyDataConverter { protected Object toSoyCompatibleObjects(Object obj) throws Exception { if (obj == null) { return obj; } if (Primitives.isWrapperType(obj.getClass()) || obj instanceof String) { return obj; } if(obj.getClass().isEnum()) { return ((Enum)obj).name(); } if (obj instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) obj; Map<String, Object> newMap = new HashMap<String, Object>(map.size()); for (String key : map.keySet()) { newMap.put(key, toSoyCompatibleObjects(map.get(key))); } return newMap; } if (obj instanceof Iterable<?>) { List<Object> list = Lists.newArrayList(); for (Object subValue : ((Iterable<?>) obj)) { list.add(toSoyCompatibleObjects(subValue)); } return list; } if (obj instanceof Callable) { final Callable<?> callable = (Callable<?>) obj; return toSoyCompatibleObjects(callable.call()); } if (obj.getClass().isArray()) { return obj; } @SuppressWarnings("unchecked") Map<String, Object> pojoMap = (Map<String, Object>) pojoToMap(obj); Map<String, Object> newMap = new HashMap<String, Object>(pojoMap.size()); for (String key : pojoMap.keySet()) { newMap.put(key, toSoyCompatibleObjects(pojoMap.get(key))); } return newMap; } DefaultToSoyDataConverter(); }
DefaultToSoyDataConverter implements ToSoyDataConverter { protected Object toSoyCompatibleObjects(Object obj) throws Exception { if (obj == null) { return obj; } if (Primitives.isWrapperType(obj.getClass()) || obj instanceof String) { return obj; } if(obj.getClass().isEnum()) { return ((Enum)obj).name(); } if (obj instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) obj; Map<String, Object> newMap = new HashMap<String, Object>(map.size()); for (String key : map.keySet()) { newMap.put(key, toSoyCompatibleObjects(map.get(key))); } return newMap; } if (obj instanceof Iterable<?>) { List<Object> list = Lists.newArrayList(); for (Object subValue : ((Iterable<?>) obj)) { list.add(toSoyCompatibleObjects(subValue)); } return list; } if (obj instanceof Callable) { final Callable<?> callable = (Callable<?>) obj; return toSoyCompatibleObjects(callable.call()); } if (obj.getClass().isArray()) { return obj; } @SuppressWarnings("unchecked") Map<String, Object> pojoMap = (Map<String, Object>) pojoToMap(obj); Map<String, Object> newMap = new HashMap<String, Object>(pojoMap.size()); for (String key : pojoMap.keySet()) { newMap.put(key, toSoyCompatibleObjects(pojoMap.get(key))); } return newMap; } DefaultToSoyDataConverter(); void setIgnorablePropertiesMatcher(
			Matcher<PropertyDescriptor> ignorablePropertiesMatcher); @Override Optional<SoyMapData> toSoyMap(final Object model); }
DefaultToSoyDataConverter implements ToSoyDataConverter { protected Object toSoyCompatibleObjects(Object obj) throws Exception { if (obj == null) { return obj; } if (Primitives.isWrapperType(obj.getClass()) || obj instanceof String) { return obj; } if(obj.getClass().isEnum()) { return ((Enum)obj).name(); } if (obj instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) obj; Map<String, Object> newMap = new HashMap<String, Object>(map.size()); for (String key : map.keySet()) { newMap.put(key, toSoyCompatibleObjects(map.get(key))); } return newMap; } if (obj instanceof Iterable<?>) { List<Object> list = Lists.newArrayList(); for (Object subValue : ((Iterable<?>) obj)) { list.add(toSoyCompatibleObjects(subValue)); } return list; } if (obj instanceof Callable) { final Callable<?> callable = (Callable<?>) obj; return toSoyCompatibleObjects(callable.call()); } if (obj.getClass().isArray()) { return obj; } @SuppressWarnings("unchecked") Map<String, Object> pojoMap = (Map<String, Object>) pojoToMap(obj); Map<String, Object> newMap = new HashMap<String, Object>(pojoMap.size()); for (String key : pojoMap.keySet()) { newMap.put(key, toSoyCompatibleObjects(pojoMap.get(key))); } return newMap; } DefaultToSoyDataConverter(); void setIgnorablePropertiesMatcher(
			Matcher<PropertyDescriptor> ignorablePropertiesMatcher); @Override Optional<SoyMapData> toSoyMap(final Object model);  }