private <T> T makeWithJSONCreator(ObjectId id, Class<T> type, DBObject rawData) {
   if (seen.contains(id))
     throw new IllegalArgumentException("Circularity when trying to construct " + id.toString());
   seen.add(id);
   // XXX: we end up unmarshalling the document twice in this case
   return unmarshaller.unmarshall(Bson.createDocument(rawData), type, this);
 }
コード例 #2
0
 private Object marshallParameter(Object parameter) {
   try {
     if (parameter == null || Bson.isPrimitive(parameter)) {
       return parameter;
     }
     if (parameter instanceof Collection) {
       return marshallCollection((Collection<?>) parameter);
     }
     if (parameter instanceof Object[]) {
       return marshallArray((Object[]) parameter);
     }
     return marshallDocument(parameter);
   } catch (Exception e) {
     String message = String.format("Unable to marshall parameter: %s", parameter);
     throw new MarshallingException(message, e);
   }
 }
  public ObjBase makeValue(ObjectId id, DBObject rawData, Class<? extends ObjBase> c) {

    if (Modifier.isAbstract(c.getModifiers()) || Modifier.isInterface(c.getModifiers())) {
      // extract declared schema from result, use that class
      Object schemaId = rawData.get(ReservedFieldNames.SCHEMA);
      try {
        c = (Class<ObjBase>) ClassUtil.findClass(schemaId.toString());
      } catch (ClassNotFoundException ex) {
        log.warn("Could not find fallback schema {}", schemaId);
        return null;
      }
    }

    ObjBase value = makeStub(id, c, rawData);
    // update stub with the rest of the data,
    if (value != null && !(value instanceof Swappable))
      try {
        unmarshaller.unmarshall(Bson.createDocument(rawData), value, this);
      } catch (MarshallingException me) {
        log.warn(me.getMessage(), me);
      }

    return value;
  }