示例#1
0
  private Object marshallDocument(Object parameter) {

    if (parameter instanceof Enum) {
      return marshallParameterAsPrimitive(parameter);
    } else {
      BsonDocument document = marshaller.marshall(parameter);

      if (hasBeenSerializedAsPrimitive(document)) {
        return marshallParameterAsPrimitive(parameter);
      } else {
        return document.toDBObject();
      }
    }
  }
示例#2
0
 /**
  * The object may have been serialized to a primitive type with a custom serializer, so try again
  * after wrapping as an object property. We do this trick only as a falllback since it causes
  * Jackson to consider the parameter as "Object" and thus ignore any annotations that may exist on
  * its actual class.
  */
 private Object marshallParameterAsPrimitive(Object parameter) {
   Map<String, Object> primitiveWrapper = Collections.singletonMap("wrapped", parameter);
   BsonDocument document = marshaller.marshall(primitiveWrapper);
   return document.toDBObject().get("wrapped");
 }
示例#3
0
 private boolean hasBeenSerializedAsPrimitive(BsonDocument document) {
   byte[] bytes = document.toByteArray();
   return bytes.length == 1 || bytes.length != bytes[0];
 }
示例#4
0
 private DBObject convertToDBObject(Object pojo, Object id) {
   BsonDocument document = marshallDocument(pojo);
   DBObject dbo = new AlreadyCheckedDBObject(document.toByteArray(), id);
   dbo.put("_id", id);
   return dbo;
 }