List of usage examples for com.liferay.portal.kernel.json JSONFactoryUtil looseDeserialize
public static Object looseDeserialize(String json)
From source file:com.liferay.screens.service.impl.ScreensDDLRecordServiceImpl.java
License:Open Source License
protected Object getFieldValue(DDMFormFieldValue ddmFormFieldValue, Locale locale) throws PortalException { Value value = ddmFormFieldValue.getValue(); String fieldValueString = value.getString(locale); if (fieldValueString == null) { return null; }/* w w w . j ava2 s. co m*/ if (fieldValueString.isEmpty()) { return null; } String dataType = ddmFormFieldValue.getType(); if (dataType.equals(FieldConstants.BOOLEAN)) { return Boolean.valueOf(fieldValueString); } else if (dataType.equals(FieldConstants.DATE)) { return fieldValueString; } else if (dataType.equals(FieldConstants.DOCUMENT_LIBRARY)) { return JSONFactoryUtil.looseSerialize(JSONFactoryUtil.looseDeserialize(fieldValueString)); } else if (dataType.equals(FieldConstants.FLOAT) || dataType.equals(FieldConstants.NUMBER)) { if (Validator.isNull(fieldValueString)) { return null; } return Float.valueOf(fieldValueString); } else if (dataType.equals(FieldConstants.INTEGER)) { if (Validator.isNull(fieldValueString)) { return null; } return Integer.valueOf(fieldValueString); } else if (dataType.equals(FieldConstants.LONG)) { if (Validator.isNull(fieldValueString)) { return null; } return Long.valueOf(fieldValueString); } else if (dataType.equals(FieldConstants.SHORT)) { if (Validator.isNull(fieldValueString)) { return null; } return Short.valueOf(fieldValueString); } return fieldValueString; }
From source file:com.liferay.sync.filter.SyncJSONHttpServletRequestWrapper.java
License:Open Source License
public boolean isSyncJSONRequest() { try {// ww w . j a va2 s. co m String cmd = getParameter(Constants.CMD); if (cmd == null) { cmd = StringUtil.read(getInputStream()); } Object jsonObject = JSONFactoryUtil.looseDeserialize(cmd); List<Object> jsonItems = null; if (jsonObject instanceof List) { jsonItems = (List<Object>) jsonObject; } else if (jsonObject instanceof Map) { jsonItems = new ArrayList<>(1); jsonItems.add(jsonObject); } for (Object jsonItem : jsonItems) { Map<String, Map<String, Object>> map = (Map<String, Map<String, Object>>) jsonItem; Set<String> keySet = map.keySet(); Iterator<String> iterator = keySet.iterator(); String key = iterator.next(); if (key.startsWith("/sync-web.") || key.startsWith("/sync-web/")) { return true; } } } catch (Exception e) { return false; } return false; }
From source file:com.liferay.sync.internal.servlet.filter.SyncJSONFilter.java
License:Open Source License
protected boolean isSyncJSONRequest(ServletRequest servletRequest) { try {//from w ww.j a v a2 s .c o m String cmd = servletRequest.getParameter(Constants.CMD); if (cmd == null) { cmd = StringUtil.read(servletRequest.getInputStream()); } Object cmdObject = JSONFactoryUtil.looseDeserialize(cmd); List<Object> jsonItems = null; if (cmdObject instanceof List) { jsonItems = (List<Object>) cmdObject; } else if (cmdObject instanceof Map) { jsonItems = new ArrayList<>(1); jsonItems.add(cmdObject); } for (Object jsonItem : jsonItems) { Map<String, Map<String, Object>> map = (Map<String, Map<String, Object>>) jsonItem; Set<String> keySet = map.keySet(); Iterator<String> iterator = keySet.iterator(); String key = iterator.next(); if (key.startsWith("/sync-web.") || key.startsWith("/sync-web/") || key.startsWith("/sync.") || key.startsWith("/sync/")) { return true; } } } catch (Exception e) { return false; } return false; }