public Json makeTyped(Object anything) {
    boolean isarray = anything.getClass().isArray();
    Class<?> type = isarray ? anything.getClass().getComponentType() : anything.getClass();
    JsonConverter converter = converterMap.get(type.getName());
    String typeName = shortNameMap.getY(type.getName());
    if (typeName == null) typeName = type.getName();
    if (isarray) {
      Json result = Json.array();
      Object[] A = (Object[]) anything;
      for (Object x : A) {
        if (x == null) result.add(Json.nil());
        else result.add(converter != null ? converter.to(x) : make(x));
      }
      return Json.object().set("javaArrayType", typeName).set("array", result);
    } else if (type.isEnum())
      return Json.object().set("java.lang.Enum", type.getName()).set("value", anything.toString());

    for (Class<?> abstractConv : converterFromAbstractMap.keySet())
      if (abstractConv.isAssignableFrom(type))
        return converterFromAbstractMap.get(abstractConv).to(anything);
    Json value = null;
    if (converter != null) value = converter.to(anything);
    else if (Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type))
      value = beanConverter.to(anything);
    else
      try {
        value = f.make(anything);
      } catch (Throwable t) {
        value = beanConverter.to(anything);
      }
    return Json.object().set("javaType", typeName).set("value", value);
  }
Exemple #2
0
 private Json getAccessPolicies(Json groups) {
   if (!groups.isArray())
     throw new IllegalArgumentException("Expected Array of cirmusergroups. e.g. legacy:311..");
   Json cirmUserGroupsWithAccessPolicies = Json.array();
   for (Json iri : groups.asJsonList()) {
     OWLIndividual group = dataFactory().getOWLNamedIndividual(fullIri(iri.asString()));
     // Here we need to make sure that the serialization stops at e.g.
     // individuals that are the objects of an AccessPolicy!
     Json groupWithAccessPolicies = OWL.toJSON(group, stopExpansionCondition);
     cirmUserGroupsWithAccessPolicies.add(groupWithAccessPolicies);
   }
   // Array of cirm groups with all access policy information serialized.
   return cirmUserGroupsWithAccessPolicies; // userdata.set("cirmusergroups",
                                            // cirmUserGroupsWithAccessPolicies);
 }