Unmarshals the given map source into a bean.
@param source the source
@return the organization
542031
public static OrganizationBean unmarshallOrganization(Map<String, Object> source) {
        if (source == null) {
            return null;
        }
        OrganizationBean bean = new OrganizationBean();
        bean.setId(asString(source.get("id")));
        bean.setName(asString(source.get("name")));
        bean.setDescription(asString(source.get("description")));
        bean.setCreatedOn(asDate(source.get("createdOn")));
        bean.setCreatedBy(asString(source.get("createdBy")));
        bean.setModifiedOn(asDate(source.get("modifiedOn")));
        bean.setModifiedBy(asString(source.get("modifiedBy")));
        postMarshall(bean);
        return bean;
    }
133344
public Object unmarshal(HierarchicalStreamReader reader,
			UnmarshallingContext context) {
		URI uri = URI.create(reader.getAttribute("uri"));
		return XExtensionManager.instance().getByUri(uri);
	}
613813
@SuppressWarnings("unchecked")
  private <T> T unmarshal() {

    try {
      instantiateEntity();
      unmarshalIdentifier();
      unmarshalKeyAndParentKey();
      unmarshalProperties();
      unmarshalEmbeddedFields();
      // If using Builder pattern, invoke build method on the Builder to
      // get the final entity.
      ConstructorMetadata constructorMetadata = entityMetadata.getConstructorMetadata();
      if (constructorMetadata.isBuilderConstructionStrategy()) {
        entity = constructorMetadata.getBuildMethodHandle().invoke(entity);
      }
      return (T) entity;
    } catch (EntityManagerException exp) {
      throw exp;
    } catch (Throwable t) {
      throw new EntityManagerException(t.getMessage(), t);
    }
  }
1289628
public static ContractBean unmarshallContract(Map<String, Object> source) {
        if (source == null) {
            return null;
        }
        ContractBean bean = new ContractBean();
        bean.setId(asLong(source.get("id")));
        bean.setCreatedBy(asString(source.get("createdBy")));
        bean.setCreatedOn(asDate(source.get("createdOn")));
        postMarshall(bean);
        return bean;
    }
276273
public static PlanBean unmarshallPlan(Map<String, Object> source) {
        if (source == null) {
            return null;
        }
        PlanBean bean = new PlanBean();
        bean.setId(asString(source.get("id")));
        bean.setName(asString(source.get("name")));
        bean.setDescription(asString(source.get("description")));
        bean.setCreatedBy(asString(source.get("createdBy")));
        bean.setCreatedOn(asDate(source.get("createdOn")));
        postMarshall(bean);
        return bean;
    }
776070
public Object javaToSql(Object source)
    {
        if (source == null)
            return null;
        try
        {
            return SerializationUtils.serialize((Serializable) source);
        }
        catch(Throwable t)
        {
            throw new ConversionException(t);
        }
    }
1228986
public static ApiEntryBean unmarshallApiEntry(Map<String, Object> source) {
        if (source == null) {
            return null;
        }
        ApiEntryBean bean = new ApiEntryBean();
        bean.setApiOrgId(asString(source.get("apiOrganizationId")));
        bean.setApiOrgName(asString(source.get("apiOrganizationName")));
        bean.setApiId(asString(source.get("apiId")));
        bean.setApiName(asString(source.get("apiName")));
        bean.setApiVersion(asString(source.get("apiVersion")));
        bean.setPlanName(asString(source.get("planName")));
        bean.setPlanId(asString(source.get("planId")));
        bean.setPlanVersion(asString(source.get("planVersion")));
        postMarshall(bean);
        return bean;
    }
1339467
@SuppressWarnings("unchecked")
  Map<String, Object> flatten(Map<String, Object> source) {
    Map<String, Object> result = new LinkedHashMap<>();

    for (String key : source.keySet()) {
      Object value = source.get(key);

      if (value instanceof Map) {
        Map<String, Object> subMap = flatten((Map<String, Object>) value);

        for (String subkey : subMap.keySet()) {
          result.put(key + "." + subkey, subMap.get(subkey));
        }
      } else if (value instanceof Collection) {
        StringBuilder joiner = new StringBuilder();
        String separator = "";

        for (Object element : ((Collection) value)) {
          Map<String, Object> subMap = flatten(Collections.singletonMap(key, element));
          joiner
              .append(separator)
              .append(subMap.entrySet().iterator().next().getValue().toString());

          separator = ",";
        }

        result.put(key, joiner.toString());
      } else {
        result.put(key, value);
      }
    }

    return result;
  }
634991
private org.jboss.marshalling.Marshaller getMarshaller(final org.jboss.marshalling.MarshallerFactory marshallerFactory)
            throws IOException {
        final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration();
        // TODO - Do we need an Object and Class table?
        marshallingConfiguration.setVersion(2);

        // TODO - Will need classloading server side to be in context of bean being called.

        return marshallerFactory.createMarshaller(marshallingConfiguration);
    }
17820
public static XContentBuilder marshall(ApiVersionBean bean) throws StorageException {
        try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
            ApiBean api = bean.getApi();
            OrganizationBean org = api.getOrganization();
            preMarshall(bean);
            builder
                .startObject()
                    .field("organizationId", org.getId())
                    .field("organizationName", org.getName())
                    .field("apiId", api.getId())
                    .field("apiName", api.getName())
                    .field("apiDescription", api.getDescription())
                    .field("version", bean.getVersion())
                    .field("status", bean.getStatus())
                    .field("createdBy", bean.getCreatedBy())
                    .field("createdOn", bean.getCreatedOn().getTime())
                    .field("modifiedBy", bean.getModifiedBy())
                    .field("modifiedOn", bean.getModifiedOn().getTime())
                    .field("publishedOn", bean.getPublishedOn() != null ? bean.getPublishedOn().getTime() : null)
                    .field("retiredOn", bean.getRetiredOn() != null ? bean.getRetiredOn().getTime() : null)
                    .field("publicAPI", bean.isPublicAPI())
                    .field("endpoint", bean.getEndpoint())
                    .field("endpointType", bean.getEndpointType())
                    .field("endpointContentType", bean.getEndpointContentType())
                    .field("parsePayload", bean.isParsePayload())
                    .field("definitionType", bean.getDefinitionType());
            Set<ApiGatewayBean> gateways = bean.getGateways();
            if (gateways != null) {
                builder.startArray("gateways");
                for (ApiGatewayBean gateway : gateways) {
                    builder.startObject()
                        .field("gatewayId", gateway.getGatewayId())
                    .endObject();
                }
                builder.endArray();
            }
            Set<ApiPlanBean> plans = bean.getPlans();
            if (plans != null) {
                builder.startArray("plans");
                for (ApiPlanBean plan : plans) {
                    builder.startObject()
                        .field("planId", plan.getPlanId())
                        .field("version", plan.getVersion())
                    .endObject();
                }
                builder.endArray();
            }
            Map<String, String> endpointProperties = bean.getEndpointProperties();
            if (endpointProperties != null) {
                builder.startObject("endpointProperties");
                for (Entry<String, String> property : endpointProperties.entrySet()) {
                    builder.field(property.getKey(), property.getValue());
                }
                builder.endObject();
            }
            builder.endObject();
            postMarshall(bean);
            return builder;
        } catch (IOException e) {
            throw new StorageException(e);
        }
    }
440722
public static Map<?, ?> toMap(File file, String encoding) throws UnmarshalException, NoSuchPathException {
		return (Map<?, ?>) toObject(file, encoding, Map.class);
	}
1341511
public BeanMappingObject getBeanMappingObject(Class src, Class target) {
        return mappings.get(mapperObjectName(src, target));
    }
187941
public static XContentBuilder marshall(RoleMembershipBean bean) throws StorageException {
        try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
            preMarshall(bean);
            builder
                .startObject()
                    .field("id", bean.getId())
                    .field("organizationId", bean.getOrganizationId())
                    .field("roleId", bean.getRoleId())
                    .field("userId", bean.getUserId())
                    .field("createdOn", bean.getCreatedOn().getTime())
                .endObject();
            postMarshall(bean);
            return builder;
        } catch (IOException e) {
            throw new StorageException(e);
        }
    }
1332409
@SuppressWarnings("unchecked")
	private Map<String, Object> toMap(final Object o) {
		if (o instanceof Map) {
			return (Map<String, Object>) o;
		}
		return BeanAccessor.asMap(o);
	}
679191
@SuppressWarnings("unchecked")
    public static Object compactJson(Object source) {
        if (source == null) return null;

        if (source instanceof List) {
            for (Object item : (List) source) {
                if (item instanceof List) {
                    compactJson(item);
                }
                else if (item instanceof Map) {
                    compactJson(item);
                }
            }
            ((List) source).removeAll(Collections.singleton(null));
        }
        else if (source instanceof Map) {
            List keysToRemove = new LinkedList();
            for (Object key : ((Map) source).keySet()) {
                Object value = ((Map)source).get(key);
                if (value instanceof List) {
                    if (((List) value).size() == 0)
                        keysToRemove.add(key);
                    else {
                        compactJson(value);
                    }
                } else if (value instanceof Map) {
                    if (((Map) value).size() == 0) {
                        keysToRemove.add(key);
                    } else {
                        compactJson(value);
                    }
                } else if (value == null) {
                    keysToRemove.add(key);
                }
            }
            for(Object key: keysToRemove) {
                ((Map) source).remove(key);
            }
        }
        else {
            throw new UnsupportedOperationException( "Only Map/String and List/Integer types are supported" );
        }

        return source;
    }
214590
public static ApiBean unmarshallApi(Map<String, Object> source) {
        if (source == null) {
            return null;
        }
        ApiBean bean = new ApiBean();
        bean.setId(asString(source.get("id")));
        bean.setName(asString(source.get("name")));
        bean.setDescription(asString(source.get("description")));
        bean.setCreatedBy(asString(source.get("createdBy")));
        bean.setCreatedOn(asDate(source.get("createdOn")));
        bean.setNumPublished(asInt(source.get("numPublished")));
        postMarshall(bean);
        return bean;
    }
29141
public static <T_Result, T_Source> List<T_Result> map(Collection<T_Source> source,
            Mapper<T_Result, T_Source> mapper) {
        List<T_Result> result = new LinkedList<T_Result>();
        for (T_Source element : source) {
            result.add(mapper.map(element));
        }
        return result;
    }